
12 Feb
2010
12 Feb
'10
2:11 p.m.
Ryan Ingram wrote:
Actually, at least in GHC, associated types are just syntax sugar for type families.
That is, this code:
class Container c where type Element c :: * view :: c -> Maybe (Element c,c)
instance Container [a] where type Element [a] = a view [] = Nothing view (x:xs) = Just (x,xs)
is the same as this code:
type family Element c :: * class Container c where view :: c -> Maybe (Element c, c) type instance Container [a] = a instance Container [a] where view [] = Nothing view (x:xs) = Just (x,xs)
OK, well in that case, I'm utterly puzzled as to why both forms exist in the first place. If TFs don't allow you to do anything that can't be done with ATs, why have them? My head hurts...