Bug in deriving Data Typeable?

Bernd Brassel bbr at informatik.uni-kiel.de
Thu Mar 12 09:05:39 EDT 2009


Hi folks,

I have been surprised by the derived instances of Data/Typeable when
using the combinator ext1Q. First look at the following definition:

> useExt1 :: Data a => a -> ()
> useExt1 = undefined `ext1Q` (\ (Just _) -> ())

> testExt1 :: ()
> testExt1 = useExt1 (Just ())

As I expected, testExt1 yields ()

But when I define my own version of Maybe and derive the Data/Typeable
instances

> data MyMaybe a = MyJust a | MyNothing deriving (Data,Typeable)

the corresponding test

> useExt1' :: Data a => a -> ()
> useExt1' = undefined `ext1Q` (\ (MyJust _) -> ())

> testExt1' :: ()
> testExt1' = useExt1' (MyJust ())

yields *** Exception: Prelude.undefined

All of this happens with both ghc 6.10.1 and 6.8.2.

Is this a bug in the derived instances, e.g., in dataCast1? If so is
there a concise tutorial telling me how to write correct instances for
the data type I'm interested in (which is not MyMaybe)?

Thanks for your time!
Bernd


More information about the Glasgow-haskell-users mailing list