[Haskell-cafe] Inverse of HaskellDB

Christopher Done chrisdone at googlemail.com
Thu Sep 30 11:25:02 EDT 2010


While we're on the topic of databases, I really wanted to try out
query/inserting from/to my database with records like this:
http://hpaste.org/40240/db_library_approach

Define a record:

data Person f =
  Person { pid        :: f Integer
         , firstName  :: f String
         , middleName :: f (Maybe String)
         , lastName   :: f String
         , age        :: f Integer
         }

then I'd query it like

personById :: Integer -> Query Person
personById i =
  Person { pid        = constant i
         , firstName  = anything
         , middleName = anything
         , lastName   = anything
         , age        = anything
         }  deriving (Typeable,Data)

Or with a Data.Default instance:

personById :: Integer -> Query Person
personById i = def { pid = constant i }

But I have yet to figure out how to derive a Typeable instance for
such a type. I don't want to write any instances of anything.
Technically I can get the field names and values using a
Data.Data.Data instance, but I don't know, maybe I should make a
TypeablePolymorphicKinds class or something and try to derive for it.
UHC's generic deriving would probably be good for something like this,
but I want GHC.


More information about the Haskell-Cafe mailing list