
Hey all, I've reduced my previous problem to a small example. Anyone know why typeOf (...) would work, but typeOf [...] would not? Is the derivation for lists funky? data Expr f = In (f (Expr f)) instance Typeable1 f => Typeable (Expr f) where typeOf (In x) = mkTyConApp (mkTyCon "TypeTest.Expr") [typeOf1 x] data Foo e = Foo deriving instance Typeable1 Foo *TypeTest> typeOf (In Foo) TypeTest.Expr TypeTest.Foo *TypeTest> typeOf [In Foo] *** Exception: Prelude.undefined

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.

On Fri, Jul 11, 2008 at 5:13 PM, Roberto Zunino
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]
Yes, that works, but what would also work is this: newtype Expr f = In (f (Expr f)) Keeping the typeOf code the same as the original. I would consider this more correct, since this is a type trick, not a value trick. The data definition makes your model have an extra bottom, which can't be very attractive! Luke
participants (3)
-
Luke Palmer
-
Roberto Zunino
-
Ron Alford