Arrow Classes
Simon Peyton-Jones
simonpj@microsoft.com
Mon, 30 Jun 2003 08:47:57 +0100
It may interest you guys to know that Ross Paterson and I have just put
syntactic support for arrows into GHC. It's only in the CVS version at
the moment, and is not documented at all, but those things will come.
The type error messages should, I hope, be a lot better than those one
can get by type checking pre-processed code.
Simon
| -----Original Message-----
| From: haskell-cafe-admin@haskell.org
[mailto:haskell-cafe-admin@haskell.org] On Behalf Of Joe
| English
| Sent: 28 June 2003 17:01
| To: haskell-cafe@haskell.org
| Subject: Re: Arrow Classes
|=20
|=20
| Ashley Yakeley wrote:
| > Wolfgang Jeltsch wrote:
| >
| > > This brings me to another point. One year ago we had a discussion
on The
| > > Haskell Mailing List concerning arrows. (The subject of the mails
was just
| > > "arrows".) The point was that it seemed strange to me that first
and second
| > > are included in the basic arrow class Arrow while left and right
have their
| > > extra class ArrowChoice. Not only that it seemed strange to me but
it made
| > > impossible to make Parser baseMonad an instance of Arrow. Parser
baseMonad
| > > has nice implementations of pure and (>>>) but none of first or
second.
| >
| > I agree. My own Arrow module hierarchy looks more or less like this:
| >
| > class Compositor comp where [...]
| > class (Compositor arrow) =3D> Arrow arrow where [...]
| > class (Arrow arrow) =3D> ProductArrow arrow where [...]
| > class (Arrow arrow) =3D> CoproductArrow arrow where [...]
| > class (ProductArrow arrow,CoproductArrow arrow) =3D> FullArrow =
arrow
| > instance (ProductArrow arrow,CoproductArrow arrow) =3D> FullArrow
arrow
| > class (Arrow arrow) =3D> ArrowFix arrow where [...]
| > class (FullArrow arrow) =3D> ApplyArrow arrow where [...]
|=20
|=20
| On that topic, see below for what mine looks like
| (from HXML, <URL: http://www.flightlab.com/~joe/hxml/ >).
|=20
| I started off with Hughes' conventions, but for some
| reason could never remember the difference between &&& and ***,
| or between ||| and +++. I found &&&, >&<, |||, >|< to have
| better mnemonic value. This also frees up +++ for ArrowPlus,
| which -- in HXML applications -- is frequently used and should
| thus be easy to type.
|=20
| When using the ArrowChoice operators, I kept tripping over all
| the 'Either' coproduct types, so added some syntactic sugar
| (borrowed from HaXML):
|=20
| data Choice a =3D a :> a
| class (Arrow a) =3D> ArrowChoice a where
| [ ... ]
| ( ?>) :: (b -> Bool) -> Choice (a b c) -> a b c
| (>?>) :: a b Bool -> Choice (a b c) -> a b c
|=20
| I found "p ?> f :> g" much more pleasant to use.
|=20
| (I also like the idea of splitting the product operators out of
| the base Arrow class -- will consider doing that in my library).
|=20
| --
|=20
| infixr 5 +++
| infixr 3 >&<, &&&
| infixr 2 >|<, |||, ?>, >?>, :>
| infixl 1 >>>
|=20
| class Arrow a where
| arr :: (b -> c) -> a b c
| (>>>) :: a b c -> a c d -> a b d
| apfst :: a b c -> a (b,x) (c,x)
| apsnd :: a b c -> a (x,b) (x,c)
| (>&<) :: a b c -> a d e -> a (b,d) (c,e)
| (&&&) :: a b c -> a b d -> a b (c,d)
| liftA2 :: (b -> c -> d) -> a e b -> a e c -> a e d
| aConst :: c -> a b c
| idArrow :: a b b
| -- Minimal implementation: arr, >>>, apfst or >&<
|=20
| data Choice a =3D a :> a
| class (Arrow a) =3D> ArrowChoice a where
| apl :: a b c -> a (Either b d) (Either c d)
| apr :: a b c -> a (Either d b) (Either d c)
| (>|<) :: a b c -> a d e -> a (Either b d) (Either c e)
| (|||) :: a b c -> a d c -> a (Either b d) c
| ( ?>) :: (b -> Bool) -> Choice (a b c) -> a b c
| (>?>) :: a b Bool -> Choice (a b c) -> a b c
| -- Minimal implementation: >|< or apl
|=20
| class (Arrow a) =3D> ArrowApply a where
| app :: a (a b c,b) c
|=20
| class (Arrow a) =3D> ArrowZero a where
| aZero :: a b c
| aMaybe :: a (Maybe c) c
| aGuard :: (b -> Bool) -> a b b
|=20
| class (Arrow a) =3D> ArrowPlus a where
| (+++) :: a b c -> a b c -> a b c
|=20
|=20
|=20
| --Joe English
|=20
| jenglish@flightlab.com
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe