
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

Hi Bernd,
I guess this might be the same issue reported some time ago (
http://thread.gmane.org/gmane.comp.lang.haskell.generics/53/focus=54): the
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.
Cheers,
Pedro
On Thu, Mar 12, 2009 at 14:05, Bernd Brassel
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 _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

José Pedro Magalhães wrote:
Hi Bernd,
I guess this might be the same issue reported some time ago ( http://thread.gmane.org/gmane.comp.lang.haskell.generics/53/focus=54): the 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.
Your link pointed me in the right direction to fix the bug for my application. Many thanks! Did you submit a bug report?

Hello,
On Thu, Mar 12, 2009 at 17:02, Bernd Brassel
Hi Bernd,
I guess this might be the same issue reported some time ago ( http://thread.gmane.org/gmane.comp.lang.haskell.generics/53/focus=54):
José Pedro Magalhães wrote: the
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.
Your link pointed me in the right direction to fix the bug for my application. Many thanks! Did you submit a bug report?
Now I did: http://hackage.haskell.org/trac/ghc/ticket/3087 Thanks, Pedro
participants (2)
-
Bernd Brassel
-
José Pedro Magalhães