Bug in deriving Data Typeable?
José Pedro Magalhães
jpm at cs.uu.nl
Thu Mar 12 09:30:52 EDT 2009
I guess this might be the same issue reported some time ago (
derived instances of Data do not define dataCast1. If you define your own
instance of Data for MyMaybe and add the definition of dataCast1 you will
get the expected behavior.
On Thu, Mar 12, 2009 at 14:05, Bernd Brassel <bbr at informatik.uni-kiel.de>wrote:
> 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
> > 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!
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Glasgow-haskell-users