[Haskell-cafe] Type arithmetic with ATs/TFs
Andrew Coppin
andrewcoppin at btinternet.com
Fri Feb 12 14:11:03 EST 2010
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...
More information about the Haskell-Cafe
mailing list