creating a relational tuple type

Hello, As an effort to learn Haskell, I am creating a relational algebra engine. To this end, I have been looking at how haskelldb handles its mapping layer. I found this: data RecNil = RecNil deriving (Eq, Ord) data RecCons f a b = RecCons a b deriving (Eq, Ord) It seems to me that the type of "b" is too loose, no? I would like "b" to be of the type RecCons or RecNil as well. The looseness of b prevents me from writing functions like this: data RecCons a b = RecCons a b | RecNil deriving (Eq, Ord) tupleLength :: RecCons a b -> Int tupleLength RecNil = 0 tupleLength (RecCons x xs) = 1 + tupleLength xs -- xs really should be of type RecCons What I would like is a list of arbitrary values rolled into a type such as (RecCons Int (RecCons String RecNil)). I tried a RecCons with existential quantification, but I ended up with a completely loosely-typed list. I would like Haskell's type engine to catch invalid comparisons between record tuples of disparate types. It seems that HDBRec works around this using a variety of typeclasses, but I don't really understand why. Thanks for any advice. Cheers, M

The type classes in Haskell DB are to allow manipulations on type level lists. You probably want to read the paper "Strongly typed heterogeneous collections" by Oleg Kiselyov, Ralf Lämmel, and Keean Schupke to get a sense of Haskell DB: http://homepages.cwi.nl/~ralf/HList/ To learn Haskell, writing a "less typed" relational algebra engine would be significantly easier. The early sections of the HList give simpler heterogeneous lists that don't use type level programming (but aren't as well typed).
participants (2)
-
AM
-
Stephen Tetley