Haskell get types of Data Constructor

Viewed 852

I was wondering if given a constructor, such as:

data UserType = User
  { username :: String
  , password :: String
  } -- deriving whatever necessary

What the easiest way is for me to get something on the lines of [("username", String), ("password", String)], short of just manually writing it. Now for this specific example it is fine to just write it but for a complex database model with lots of different fields it would be pretty annoying.

So far I have looked through Typeable and Data but so far the closest thing I have found is:

user = User "admin" "pass"
constrFields (toConstr user)

But that doesn't tell me the types, it just returns ["username", "password"] and it also requires that I create an instance of User.

1 Answers
Related