[Haskell-cafe] Aren't type system extensions fun?

Miguel Mitrofanov miguelimo38 at yandex.ru
Mon May 26 17:28:18 EDT 2008

> class Typable x => Term x where
>   gmapT :: (forall y. Term y => y -> y) -> x -> x

In "gmapT f x" the function f must be of type "forall y. Termy => y ->  
y". That means that for EACH type y which is an instance of "Term"  
class, f maps y to y. You can't do something like "gmapT (+ 1) x",  
since (+ 1) is not general enough.

However, if, say, Term class provides a method

class Term a where
    pnt :: a

then you CAN do, for example, "gmapT (const pnt) x", since the type of  
"const pnt" is general enough (and even more general).

> At this point, I am at a complete loss as to how this is any  
> different from
> gmapT :: Term y => (y -> y) -> x -> x

Here you CAN do "gmapT (+ 1) x", assuming that, say, Int is an  
instance of Term class.

More information about the Haskell-Cafe mailing list