John Goerzen wrote:
On 2008-02-20, John Goerzen <[EMAIL PROTECTED]> wrote:
I notice that Data.Foldable does some similar things but does not use
multi-parameter type classes.  I seem to recall that I attempted to do
this in the same manner, but got tripped up somewhere.  I can't
remember now exactly what the problem was, but I can go back and look
if nobody knows off-hand.

I went back and looked.

The problem is that ByteString doesn't work as a member of Foldable,
or of ListLike without it being MPTC.  Trying to do so yields:

ListLike.hs:217:20:
    Kind mis-match
    Expected kind `* -> *', but `BS.ByteString' has kind `*'
    In the instance declaration for `F.Foldable BS.ByteString'

Is there any way around that, other than MPTC?

Not directly, no.

The point about Foldable, Functor, and Monad, is that they enforce the connection between container and contents. If the contents is of type "a", the container is of type "f a" for a fixed type constructor 'f'. This works for [], Seq, and so on, but fails for ByteString.

To go to the next level, for ByteString you either need type-level functions (to generalise 'f' from "type constructor" to "arbitrary function :: * -> *"), or MPTCs (to make the association between container and contents explicit).

However, passing around dictionaries is certainly a solution which works in haskell98. I haven't thought it through enough to see if it would be unpleasantly verbose in practice.

Jules
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to