Generics...(ish)
Simon Peyton-Jones
simonpj at microsoft.com
Wed Jan 28 12:56:01 EST 2004
Try the new stuff (in GHC6.2) in the Data.Generics library.
In particular the class Data, and its related types Constr and DataType
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data.Generics
.Basics.html
Ralf and I are writing a paper about the extensions you'll find there,
which aren't in our original "scrap your boilerplate" paper.
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: 21 January 2004 12:35
| To: glasgow-haskell-users at haskell.org
| Subject: Generics...(ish)
|
|
| I am currently using template haskell to generate code to work on a
| record data type... This however is not very pretty, and I wondered if
| there was another way to do what I want in GHC. I need to iterate over
| the contents of a record for example:
|
| data Test = Test { a :: Int, b :: String, c :: Float }
|
| If I derive Typeable, I can compare the data-type, but not decompose
it,
| I don't know much about generics, and was wondering if I might be able
to
| do it that way...
|
| The functionality I need is equivalent to being able to compare to
instances,
| for example, consider the type above, and the type below:
|
| data Test2 = Test2 { x :: Int, y :: String, z :: Float, zz :: String }
|
| i need to construct a function that could output the differenc between
the
| types, position at a time, so for the above the output would be:
|
| Test2 contains extra String field.
|
| or if "y" was to have the type Float,
|
| Position 2 : Types differ (Test has String, Test2 has Float)
| Test2 contains extra String field.
|
|
| I could do this easily if Typeable was a concrete type just by using
| case statements...
|
| Regards,
| Keean Schupke.
| _______________________________________________
| 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