
look at the user manual.
Okay, I see the Generic type class stuff does not support multi parameter type classes. I guess I am stuck - any suggestions as to how best do this? I wish to be able to derive type level labels for datatypes, like the following: data Fred a = Fred a deriving TTypeable generates the instance: instance TTypeable a al => TTypeable (Fred a) (NCons (N3 (N4 (N5 Nil))) (TCons al Nil)) where (N3 (N4 (N5 Nil))) is the result of a hash function on the name "Fred". I have looked at TcDeriv but I don't know enough of the compiler internals to see how this would be added to the current implementation... Can you give me some pointers on how to do this? Keean.

On 13/10/2004, at 10:02 AM, MR K P SCHUPKE wrote:
Okay, I see the Generic type class stuff does not support multi parameter type classes. I guess I am stuck - any suggestions as to how best do this?
I wish to be able to derive type level labels for datatypes, like the following:
data Fred a = Fred a deriving TTypeable
generates the instance:
instance TTypeable a al => TTypeable (Fred a) (NCons (N3 (N4 (N5 Nil))) (TCons al Nil))
If you are happy to live on the edge a bit (which you seem to be happy with, considering that you're playing with GHC CVS ;), Template Haskell might be one way to do it. See "Template Haskell: A Report from the Field", a paper where Ian Lynagh does exactly what you're trying to do: http://www.haskell.org/th/papers.html -- % Andre Pang : trust.in.love.to.save

Yes, I could quite easily write the generator in TemplateHaskell (have played with it before) _but_ I don't like the $(xxx) syntax... Perhaps if Simon could be persuaded to allow deriving clauses to be defined in TH? data X x = X x $(deriveMyClass (reify X)) could perhaps be defined from data X x = X x deriving MyClass I saw the same suggestion earlier today on the Haskell list... Keean. Andre Pang wrote:
On 13/10/2004, at 10:02 AM, MR K P SCHUPKE wrote:
Okay, I see the Generic type class stuff does not support multi parameter type classes. I guess I am stuck - any suggestions as to how best do this?
I wish to be able to derive type level labels for datatypes, like the following:
data Fred a = Fred a deriving TTypeable
generates the instance:
instance TTypeable a al => TTypeable (Fred a) (NCons (N3 (N4 (N5 Nil))) (TCons al Nil))
If you are happy to live on the edge a bit (which you seem to be happy with, considering that you're playing with GHC CVS ;), Template Haskell might be one way to do it. See "Template Haskell: A Report from the Field", a paper where Ian Lynagh does exactly what you're trying to do:

Keean Schupke
Yes, I could quite easily write the generator in TemplateHaskell (have played with it before) _but_ I don't like the $(xxx) syntax... Perhaps if Simon could be persuaded to allow deriving clauses to be defined in TH?
data X x = X x $(deriveMyClass (reify X))
could perhaps be defined from
data X x = X x deriving MyClass
I saw the same suggestion earlier today on the Haskell list...
Check out Ulf Norell's IOHCC submission, his DeriveData.hs module does this, though I can't tell if it will work for parameterized types. -- Shae Matijs Erisson - Programmer - http://www.ScannedInAvian.org/ "I will, as we say in rock 'n' roll, run until the wheels come off, because I love what I do." -- David Crosby

Keean Schupke
writes: Yes, I could quite easily write the generator in TemplateHaskell (have played with it before) _but_ I don't like the $(xxx) syntax... Perhaps if Simon could be persuaded to allow deriving clauses to be defined in TH?
data X x = X x $(deriveMyClass (reify X))
could perhaps be defined from
data X x = X x deriving MyClass
I saw the same suggestion earlier today on the Haskell list...
Check out Ulf Norell's IOHCC submission, his DeriveData.hs module does this, though I can't tell if it will work for parameterized types.
It doesn't. A version that does can be downloaded from http://www.cs.chalmers.se/~ulfn/th/DeriveData.hs / Ulf

Okay so that does the deriving... How are you deriving the constraints? (in the ghc code there is some equaion expansion, where it finds the fixed point). Still the main point was that it would be nice to seamlessly integrate this... Surely it wouldn't take much to get the compiler to look for a template-haskell splice $(derivingX) when the compiler encounters a "deriving X" statement that is not built-in? Ulf Norell wrote:
Keean Schupke
writes: Yes, I could quite easily write the generator in TemplateHaskell (have played with it before) _but_ I don't like the $(xxx) syntax... Perhaps if Simon could be persuaded to allow deriving clauses to be defined in TH?
data X x = X x $(deriveMyClass (reify X))
could perhaps be defined from
data X x = X x deriving MyClass
I saw the same suggestion earlier today on the Haskell list...
Check out Ulf Norell's IOHCC submission, his DeriveData.hs module does this, though I can't tell if it will work for parameterized types.
It doesn't. A version that does can be downloaded from
http://www.cs.chalmers.se/~ulfn/th/DeriveData.hs
/ Ulf
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (5)
-
Andre Pang
-
Keean Schupke
-
MR K P SCHUPKE
-
Shae Matijs Erisson
-
Ulf Norell