Is generic information dumpable?

Hi, I am learning the new generic feature of ghc. I'd have to say, it is harder than template to enter. When I started to learn template, ghc -ddump-slices really helped. So I wonder if I could get the representation generated when deriving Generic. I think that would be a great help. -- 竹密岂妨流水过 山高哪阻野云飞

"-ddump-deriv" will print (most of) it. Cheers, Pedro On Thu, Nov 3, 2011 at 16:26, Magicloud Magiclouds < magicloud.magiclouds@gmail.com> wrote:
Hi, I am learning the new generic feature of ghc. I'd have to say, it is harder than template to enter. When I started to learn template, ghc -ddump-slices really helped. So I wonder if I could get the representation generated when deriving Generic. I think that would be a great help. -- 竹密岂妨流水过 山高哪阻野云飞
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2011/11/3 José Pedro Magalhães
"-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

Hi,
2011/11/3 Bas van Dijk
2011/11/3 José Pedro Magalhães
: "-ddump-deriv" will print (most of) it.
But it doesn't print the most useful piece of information: the definition of Rep.
Yes... I am aware of this.
It would be great if this could be added.
I'll do it. Cheers, Pedro

2011/11/4 José Pedro Magalhães
Hi,
2011/11/3 Bas van Dijk
2011/11/3 José Pedro Magalhães
: "-ddump-deriv" will print (most of) it.
But it doesn't print the most useful piece of information: the definition of Rep.
Yes... I am aware of this.
It would be great if this could be added.
I'll do it.
Cheers, Pedro
Great, thanks!

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
2011/11/3 José Pedro Magalhães
: "-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

Thanks José!
Will this make it into ghc-7.4?
Bas
2011/11/4 José Pedro Magalhães
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
2011/11/3 José Pedro Magalhães
: "-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

2011/11/4 Bas van Dijk
Thanks José!
Will this make it into ghc-7.4?
Yes, I think so. Cheers, Pedro
Bas
2011/11/4 José Pedro Magalhães
: 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
2011/11/3 José Pedro Magalhães
: "-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
participants (3)
-
Bas van Dijk
-
José Pedro Magalhães
-
Magicloud Magiclouds