[Haskell-cafe] SYB, ext1Q, and deriving custom Typeable and Data instances

Vyacheslav Akhmechet coffeemug at gmail.com
Mon Dec 4 22:19:08 EST 2006


I'm trying to use SYB to implement some basic relational persistance.
I define a PKey datatype to represent primary keys like this:

newtype PKey a = PKey a
              deriving (Show, Typeable, Data)

I then define a sample data type like this:

data User = User {
      id :: PKey Int,
      firstName :: String,
      lastName :: String,
    } deriving (Show, Typeable, Data)

Finally, I try to iterate over the structure like this:

test = gmapQ (gshow `ext1Q` aux)
    where aux :: PKey a -> String
          aux _ = "test"

The problem is that for id gmapQ calls gshow instead of my customized
version (aux). I've seen a discussion on this on haskell cafe at the
following URL:


I couldn't understand the following details:
1. Do I need to derive both Typeable and Data instances?
2. Do I need to derive them for both PKey and User or just PKey?
3. Where can I find sample code to derive these instances?
Documentation shows a sample of how GHC derives Data, is that a good
template to use? Also, what's a good example to derive Typeable (if in
fact it needs to be done manually)?

 - Slava.

More information about the Haskell-Cafe mailing list