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

Stuart Hungerford stuart.hungerford at gmail.com
Sat Mar 21 21:53:27 UTC 2015


On Sat, Mar 21, 2015 at 7:31 PM, Chris Wong <lambda.fairy at gmail.com> wrote:

>>> [...]
>>> 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
> [...]

If I also planned to have M instances like

instance M Float Float where ...

instance M Int Float where ...

instance (M r g) => M r  [g] where ...

instance (M s u, M s v) => M s (u, v) where ...

Which of the three approaches would make for the most idiomatic
Haskell (add extra 'r' parameter, functional dependencies or
associated types)?  Is it common to require a range of language
extension pragmas to make this kind of thing work or am I just going
about this in a non-idiomatic way?

Thanks,

Stu


More information about the Haskell-Cafe mailing list