Proposal: Add Compositor class as superclass of Arrow

Ashley Yakeley ashley at semantic.org
Sat Oct 13 04:23:27 EDT 2007


http://hackage.haskell.org/trac/ghc/ticket/1773
(darcs patch attached to ticket)

The Compositor class has two members:

  class Compositor comp where
    identity :: comp a a
    (>>>) :: comp a b -> comp b c -> comp a c

with the obvious monoid. Since all Arrows are Compositors, make 
Compositor a superclass of Arrow.

A number of useful types are Compositors but not Arrows:

1. Bijections

   data Bijection a b = MkBijection (a -> b) (b -> a)

2. Codecs, i.e. encoder/decoder pairs such as charset converters

   data Codec base derived = MkCodec
   {
     encode :: derived -> base,
     decode :: base -> Maybe derived -- or other Monad
   }

   utf8 :: Codec [Word8] String
   xml :: Codec String XML

3. Lenses
These make updatable sections of data structures.

   data Lens s t = MkLens
   {
     lensGet :: s -> t,
     lensPutback :: t -> s -> s
   }

See http://www.cis.upenn.edu/~bcpierce/papers/lenses-etapsslides.pdf

4. Reified proofs of type identity
   These are useful if you use GADTs and type-witnesses a lot.

   newtype SameType a a' = MkSameType (forall f. f a -> f a')

Proposal period: two weeks, until 10-27



More information about the Libraries mailing list