[Haskell] Help on Arrows

David Menendez zednenem at psualum.com
Sat Jan 15 19:03:45 EST 2005


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 at psualum.com> <http://www.eyrie.org/~zednenem/>


More information about the Haskell mailing list