[Haskell-cafe] Multi-param typeclass vs locally constrained typeclass methods

Roman Cheplyaka roma at ro-che.info
Wed Sep 18 14:54:16 CEST 2013

* Jacques Carette <carette at mcmaster.ca> [2013-09-18 08:21:51-0400]
> Could someone please explain what the difference (if any!), in
> semantics is between
> class Foo f => Bar f g where
>   method1 :: f a -> g a
> and
> class Bar' g where
>   method2 :: Foo f => f a -> g a

Bar is more flexible than Bar'. If you have n types, you can write n^2
Bar instances (potentially having very different semantics) to convert
between them.

You can only write n Bar' instances, on the other hand. In these
instances you can dispatch based on 'g' but not on 'f'. 'f' is abstract,
and you only can access it through the Foo interface.

So they are quite different.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130918/6836da44/attachment.pgp>

More information about the Haskell-Cafe mailing list