Slide 10
Slide 10 text
Some examples.
ordinary functions are an instance of arrow
instance Arrow (->) where
arr = id
(>>>) = flip (.)
first f = f x id
we can define a state transformer as an arrow.
type State z a b = (z,a) -> (z,b)
instance Arrow (State z) where
arr f = ST (id x f)
ST f >>> ST g = ST (g . f)
first (ST f) = ST (assoc . (f x id) . unassoc
where
unassoc (val, (state, c)) = ((val,state),c)
fetch :: State z () z
fetch = ST (\(s,()) -> (s,s))
store :: State z z ()
store = ST (\(s,s’) ->(s’,()))