arrows-0.4/0.4.1 + Stream: Monoid instances

Marc A. Ziegert coeus at
Sat Nov 29 03:49:03 EST 2008


i've just had serious problems with too many (or too strange) Monoid instances in the arrows library.
i tried to install/patch Conal Elliott's bot package, which reinterprets some arrow types, i.e.
  type StreamBot = StreamArrow (->)
and then tries to derive the Monoid instance with
  deriving instance Monoid o => Monoid (StreamBot i o).

the main problem is the circumstance, that the instance of StreamArrow as Monoid depends strangely on ArrowPlus, but (->) is no instance of the ArrowPlus class.
  instance ArrowPlus a => Monoid (StreamArrow a b c)
  instance ArrowPlus a => Monoid (XyzArrow a b c)
(->) makes only sense to be in MonadPlus, iff (a->b) is a Monoid -- which is, iff b is a Monoid; and that dependency does not work:
  instance Monoid b => ArrowPlus (->) where...?!

INHO it does not make any sense at all to derive the Monoid instance from ArrowPlus instead of other Monoids.
so, is it possible to remove them? anyway, they are only copies of MonadPlus.

additionally, if it is possible and does not cause too many problems in other packages, i suggest to generalize the Monoid instance for (->), which is located at Data.Monoid.
i.e. like this:

instance (Arrow (~>),Monoid c) => Monoid ((~>) b c) where
  mempty = arr (const mempty)
  mappend f g = (f &&& g) >>> arr (uncurry mappend)

besides that, i miss a Monoid instance for Streams, which should be located in the corresponding library:

instance Monoid x => Monoid (Stream x) where
  mempty = Cons mempty mempty
  mappend (Cons a as) (Cons b bs) = mappend a b `Cons` mappend as bs

- marc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url :

More information about the Libraries mailing list