[Haskell-cafe] Re: [Haskell] Swapping parameters and type classes

Bas van Dijk v.dijk.bas at gmail.com
Mon Sep 17 15:29:14 EDT 2007


On 9/16/07, Mads Lindstrøm <mads_lindstroem at yahoo.dk> wrote:
> Hi all
>
> If I have this type:
>
>   data Foo a b = ...
>
> and this class
>
>   class Bar (x :: * -> *) where ...
>
> I can imagine two ways to make Foo an instance of Bar. Either I must
> "apply" the 'a' or the 'b' in (Foo a b). Otherwise it will not have the
> right kind. To "apply" the 'a' I can do:
>
>   instance Bar (Foo a) where ...
>
> But what if I want to "apply" the 'b' ? How do I do that ?
>
>
> Greetings,
>
> Mads Lindstrøm
>
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>


(Redirecting to Haskell-Cafe)

I think the easiest way to make it work is with a newtype wrapper
around 'Foo a b' that swaps the arguments, like Brent mentioned.

Without it you need some kind of type level lambda abstraction. Something like:

instance Bar (\x -> Foo x b) where ...

But this is not valid Haskell.

cheers,

Bas


More information about the Haskell-Cafe mailing list