A couple of hours ago I built GHC HEAD to experiment with new shiny closed type families.
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}
type family C a b where
C a [a] = [a]
C a a = [a]
Now I try to put C
to use:
class Combine a b where
combine :: a -> b -> C a b
instance Combine a [a] where
combine a b = a : b
instance Combine a a where
combine a b = [a, b]
Which results in this error:
Couldn't match expected type ‛C a a’ with actual type ‛[a]’
...
In the expression: [a, b]
In an equation for ‛combine’: combine a b = [a, b]
In the instance declaration for ‛Combine a a’
It seems to me that the second equation is apart from the first one ([a] a
can’t be simplified to a a
, no matter what a
), so why doesn’t it compile?
C a a = a
to beC a a = [a]
or the second instance to becombine a b = a++b
? – MdxBhmtC [a] a = [a]
butinstance Combine a [a]
? – Vladimir Matveev