In my current pondering of the compose-able objects them, I was thinking
it would be useful to have the follow abstractions: Monoids, which were
themselves tuples of Monoids. The idea was something like so:

code:
--------
import Data.Monoid

instance Monoid (Socket2 a b) where

  mempty = Socket2 (mempty, mempty)

  Socket2 (a, b) `mappend` Socket2 (w, x) = Socket2 (a `mappend` w, b
`mappend` x)

data Socket2 a b = Socket2 (a, b)
--------

However, this does not compile because of errors like so:

code:
--------
Sockets.hs:9:21:
    No instance for (Monoid a)
      arising from a use of `mempty'
    In the expression: mempty
    In the first argument of `Socket2', namely `(mempty, mempty)'
    In the expression: Socket2 (mempty, mempty)
--------

This makes sense, but I haven't figured out a way to rewrite this to
make it work. One approach I tried was to encode Monoid constraints into
the data declaration (which I heard was a bad idea) but this didn't
work, even using forall. Also I tried to encode it into the instance
declaration, but the compiler kept complaining about errant or illegal
syntax.

-- 
frigidcode.com

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to