[Haskell-cafe] Re: Combining Wouter's expressions with extensible
records
Antoine Latter
aslatter at gmail.com
Fri Jul 11 12:50:51 EDT 2008
On Fri, Jul 11, 2008 at 7:07 AM, Ron Alford <ronwalf at volus.net> wrote:
> What's odd is that it works directly (typeOf ... (Expr (f :+: g))
> returns a type), but if you enclose the expression in a list, it fails
> with Prelude.undefined. Do I also need a custom instance for
> Typeable [Expr ...] ? (See previous message for code)
>
The problem is that the List instance is playing the same dirty tricks
with it's 'typeOf' implementation as we are: it's asking us the type
of one of the list elements by passing in "undefined" to our "typeOf1"
implementation.
And then your "typeOf1" implementation tries to do pattern matching on
undefined.
Here is what will work:
instance (Typeable1 f, Typeable1 g) => Typeable1 (f :+: g) where
typeOf1 x = mkTyConApp (mkTyCon "Planning.Wouter.:+:") [typeOf1
left, typeOf1 right]
where
(Inr right) = Inr undefined `asTypeOf` x
(Inl left) = Inl undefined `asTypeOf` x
Now we never do pattern matching on our input.
This has been pretty educational.
-Antoine
More information about the Haskell-Cafe
mailing list