Generics and type classes
Simon Peyton-Jones
simonpj at microsoft.com
Mon Feb 2 11:58:14 EST 2004
What you ask is not easy. When you ask for
everywhere special
you ask to apply special to each node of the tree -- and special
requires the MyClass dictionary. But the library code for 'gmapT' and
'everywhere' don't know about MyClass. In particular, to do (gmapT
special), poor old gmapT has to find a MyClass dictionary to pass to
each call to special -- and it has no way to do that.
I bet that you could do what you want by replacing the 'instance MyClass
ExampleType1' by mkTs for special, so special uses run-time type
dispatch to implement the operations in MyClass. I guess that's what
Keeane is suggesting.
Simon
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org
[mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of MR K P SCHUPKE
| Sent: 02 February 2004 11:48
| To: doc at drjava.de; glasgow-haskell-users at haskell.org
| Subject: Re: Generics and type classes
|
| Because the 'cast' operator used in generics, works on having a
concrete
| type to cast to. What you need to do is:
|
| module TypeTest where
|
| import Data.Generics
|
| class Data a => MyClass a
|
| instance MyClass ExampleType1
| instance MyClass ExampleType2
|
| special :: ExampleType1 -> ExampleType1
| special = ...
|
| special2 :: ExampleType2 -> ExampleType2
| special2 = ...
|
| generic :: MyClass a => a -> a
| generic = everywhere (mkT special `extT` special2 ...)
|
| Regards,
| Keean.
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list