[Haskell-cafe] Is generic information dumpable?
José Pedro Magalhães
jpm at cs.uu.nl
Fri Nov 4 11:25:17 CET 2011
Hi,
Now, for the following datatype:
data X a = X { myX :: a } deriving Generic
You get the following -ddump-deriv output:
==================== Derived instances ====================
Derived instances:
instance GHC.Generics.Generic (Temp.X a_adY) where
GHC.Generics.from (Temp.X g1_aeG)
= GHC.Generics.M1
(GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1_aeG)))
GHC.Generics.to
(GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1
g1_aeH))))
= Temp.X g1_aeH
instance GHC.Generics.Datatype Temp.D1X where
GHC.Generics.datatypeName _ = "X"
GHC.Generics.moduleName _ = "Temp"
instance GHC.Generics.Constructor Temp.C1_0X where
GHC.Generics.conName _ = "X"
GHC.Generics.conIsRecord _ = GHC.Types.True
instance GHC.Generics.Selector Temp.S1_0_0X where
GHC.Generics.selName _ = "myX"
Generic representation:
Generated datatypes for meta-information:
Temp.D1X
Temp.C1_0X
Temp.S1_0_0X
Representation types:
Temp.Rep_X = GHC.Generics.D1
Temp.D1X
(GHC.Generics.C1
Temp.C1_0X
(GHC.Generics.S1 Temp.S1_0_0X (GHC.Generics.Par0
a_adY)))
Still not perfect, in that the representation type should really appear as
a type instance inside the Generic instance, but at least all the important
information is printed.
Cheers,
Pedro
2011/11/3 Bas van Dijk <v.dijk.bas at gmail.com>
> 2011/11/3 José Pedro Magalhães <jpm at cs.uu.nl>:
> > "-ddump-deriv" will print (most of) it.
>
> But it doesn't print the most useful piece of information: the
> definition of Rep.
>
> It would be great if this could be added.
>
> Currently when I have a type that I want to know the Rep of, say:
>
> data Foo = Bar Int
> | Boo {hello :: String}
> deriving Generic
>
> I just convert it to a Rep and show it:
>
> err = show $ from $ Boo "World"
>
> However Reps don't have Show instances so GHC complains:
>
> No instance for
> (Show (D1 D1Foo ( C1 C1_0Foo (S1 NoSelector (Rec0 Int))
> :+: C1 C1_1Foo (S1 S1_1_0Foo (Rec0 String))
> )
> x0
> )
> )
> arising from a use of `show'
>
> And there you go. This is the only time when I'm happy to see an error
> message :-)
>
> Bas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111104/42e140c8/attachment.htm>
More information about the Haskell-Cafe
mailing list