
Hi, I have just discovered Generics in Haskell and, writing some code with GHC, I wondered about the portability of my code. It is possible I overlooked something in the GHC documentation but I did not found a way to obtain, let say, the haskell code for the derived classes. I mean, having the following type declaration :
data Something = This | That deriving (Eq, Ord, Typeable, Data)
I can use the -fgenerics to automatically derive instances for Something. But I could wish to have the generated source code for those instances (like, I suppose, the DrIft tool does), for instance, to compile my source with another compiler, which does not support Generics. Is that possible ? Thank you, Fernand

Hi
I have just discovered Generics in Haskell and, writing some code with GHC, I wondered about the portability of my code.
If you use Data.Generics, your code is not portable - no other Haskell implementation supports the necessary bits.
I can use the -fgenerics to automatically derive instances for Something. But I could wish to have the generated source code for those instances (like, I suppose, the DrIft tool does), for instance, to compile my source with another compiler, which does not support Generics.
Use Derive, which does support Generics: http://www-users.cs.york.ac.uk/~ndm/derive/ If you care about portability, and are not using some of the more advanced features of Generics, then you might want to take a look at Uniplate: http://www-users.cs.york.ac.uk/~ndm/uniplate/ Uniplate does generic traversals, but will work on all Haskell 98 compilers, to some degree - read the paper for exact details. Thanks Neil

Neil Mitchell a écrit :
Use Derive, which does support Generics: http://www-users.cs.york.ac.uk/~ndm/derive/
If you care about portability, and are not using some of the more advanced features of Generics, then you might want to take a look at Uniplate: http://www-users.cs.york.ac.uk/~ndm/uniplate/
Uniplate does generic traversals, but will work on all Haskell 98 compilers, to some degree - read the paper for exact details.
Thanks
Neil
Thanks for these links. I will check the tool, but they seem to fit perfectly for my purposes. Fernand
participants (2)
-
Fernand
-
Neil Mitchell