[Haskell-cafe] FGL instance constraint

Jason Dagit dagit at codersbase.com
Sat May 1 02:30:21 EDT 2010


On Fri, Apr 30, 2010 at 11:08 PM, Ivan Lazar Miljenovic <
ivan.miljenovic at gmail.com> wrote:
>
>
> You're putting the constraint in the wrong places: put the "(Cls a) => "
> in the actual functions where you need it.
>

That's solid advice in general, but it's still not going to work here if any
of the functions needed for the instance of Graph require the type class
constraint.

The same problem comes up some times with the Monad class.  For example, if
you wanted to make a monad instance for Set a, you need "(Ord a) => " in the
instance functions.

I think associated types can work around this, if Graph used them for the a
and b types, but I've never tried that so I don't actually know how it
works.

A solution to the monad problem I just mentioned is outlined here as
'restricted monads':
http://okmij.org/ftp/Haskell/types.html#restricted-datatypes

Perhaps you can try either associated types or the restricted monad
approach?  Unfortunately, I think both of them require you to change FGL
instead of just your code, although maybe not with the restricted monad
stuff.  I don't recall how invasive that approach is.

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100501/dbaee833/attachment.html


More information about the Haskell-Cafe mailing list