[Haskell-cafe] [Haskell-beginners] Multi-parameter type classes and ambiguous type variables...

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Sat Mar 21 07:37:52 UTC 2015


This might be better answered at the haskell-cafe. Sending to cafe.

On 21 March 2015 at 03:09, Stuart Hungerford <stuart.hungerford at gmail.com>
wrote:

> Hi,
>
> As a learning exercise I'm modelling some algebraic structures as
> Haskell typeclasses. Some of these are multi-parameter type classes.
> Here's a very simplified version of the type class relationships:
>
> class MM a where
>   one :: a
>
> class AM a where
>   zero :: a
>
> class (AM a, MM a) => SR a
>
> class (AM a) => AG a where
>   inv :: a -> a
>
> class (SR a) => R a where
>   neg :: a -> a
>
> class (R r, AG g) => M r g where
>   sca :: r -> g -> g
>
> check :: (Eq g, M r g) => g -> Bool
> check x = sca one x == x
>
> The problem I have is that GHC is finding the "r" type variable in the
> "check" function ambiguous. Given my still limited Haskell knowledge
> I'm not surprised this is happening. What I would like to know is how
> experienced Haskellers handle this situation in practice: is there an
> idiomatic way of disambiguating "r" or is it a sign of poor type class
> design?
>
> Thanks,
>
> Stu
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150321/89031a5c/attachment.html>


More information about the Haskell-Cafe mailing list