I\'m trying to understand arrow notation, in particularly how it works with Monads. With Monads I can define the following:
f = (*2)
g = Just 5 >>= (return
First we need an arrow with the same semantics as the Maybe
monad. We could define it from scratch, but the easiest way is to wrap the Maybe
monad into Kleisli:
type MaybeArrow = Kleisli Maybe
Then we'll also need a way how to run this monad to extract the result:
runMaybeArrow :: MaybeArrow () a -> Maybe a
runMaybeArrow = flip runKleisli ()
Also it'll be handy to have a way how to create a constant arrow from a given value (which just ignores its input):
val :: (Arrow a) => c -> a b c
val = arr . const
And finally, we get:
g' = runMaybeArrow (val 5 >>> arr f)