[Haskell-cafe] Typeable and fancy types

Roberto Zunino zunino at di.unipi.it
Fri Jul 11 13:13:35 EDT 2008


Ron Alford wrote:
> instance Typeable1 f => Typeable (Expr f) where
>     typeOf (In x) = mkTyConApp (mkTyCon "TypeTest.Expr") [typeOf1 x]

       typeOf ~(In x) = mkTyConApp (mkTyCon "TypeTest.Expr") [typeOf1 x]

Lazy patterns are jolly useful here.

Remember that typeOf will be usually called on _|_, so it must not 
inspect its argument.

Also, dummy functions such as

   getC :: Foo a b c d -> c
   getC _ = undefined

can be exploited in

   typeOf x = ... typeOf (getC x) ...

Zun.




More information about the Haskell-Cafe mailing list