Hi folks, I would like to use Arrows, but I just can't figure out how to actually use them. I looked at various documentations including the API doc [1], the Wiki [2], [3], and some random pages on the net but didn't find a single simple example that tells me how to apply an Arrow to a value. Assume I have the extremly simple arrow such as:
MyAdd1A :: (Arrow a, Num b) => a b b MyAdd1A = arr (\ x -> x + 1 )
I am probably totally wrong, buy I look for something like evaluateArrow with the type:
evaluateArrow :: (Arrow a) => a b c -> b -> c to use it like: main = do let x = evaluateArrow $ MyAdd1A 1 print x
Please enlighten me! Georg [1] http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control.Arrow.htm... [2] http://haskell.org/hawiki/UnderstandingArrows [3] http://www.haskell.org/arrows/ -- ---- Georg Martius, Tel: (+49 34297) 89434 ---- ------- http://www.flexman.homeip.net ---------
Georg Martius writes:
Hi folks,
I would like to use Arrows, but I just can't figure out how to actually use them. I looked at various documentations including the API doc [1], the Wiki [2], [3], and some random pages on the net but didn't find a single simple example that tells me how to apply an Arrow to a value.
It depends on the type of the arrow. Arrows of type (->) can be applied directly, because they're just plain functions. Arrows of type 'Kleisli m' can be applied using a simple 'runKleisli' function. runKleisli :: Kleisli m a b -> a -> m b runKleisli (Kleisli f) = f (I'm not sure why this isn't in Control.Arrow in the first place.) Using your example arrow, we can use ($) and 'runKleisli' to coerce it into functions of various types. myAdd1A :: (Arrow a, Num b) => a b b myAdd1A = arr (\x -> x + 1) ($) myAdd1A :: Num b => b -> b runKleisli myAdd1A :: (Monad m, Num b) => b -> m b More interesting arrows, like the signal processors in Yampa [4], may not have a meaningful concept of application. [4] <http://www.haskell.org/yampa/> -- David Menendez <zednenem@psualum.com> <http://www.eyrie.org/~zednenem/>
participants (2)
-
David Menendez -
Georg Martius