|
From: Frederik E. <fre...@a5...> - 2005-02-22 21:18:51
|
On Tue, Feb 22, 2005 at 09:51:35PM +0100, Shae Matijs Erisson wrote:
> Frederik Eaton <fre...@a5...> writes:
>
> > Is there anyone on this list?
>
> Me me! I'm here! I haven't gotten around to reading the HList paper though,
> so I won't be able to give you intelligent feedback on your code till I do.
Oh, don't read the whole paper, in fact you probably don't need to
read any of it, most of it goes far beyond what I use, which is pretty
self-explanatory.
data a :* l = a :. l
data HNil = Nil
e.g.
-- x :: Bool :* String :* Int :* HNil
x = True :. "Hi" :. 4 :. Nil
It's just a way of giving you something like a tuple type, but with
access to the internals so you can make instances based on the
structure. The important part of my module is:
instance SqlRow HNil where
getFieldValues s [] = return Nil
getFieldValues s _ = fail "Wrong number of fields"
instance (SqlBind a, SqlRow l) => SqlRow (a :* l) where
getFieldValues s (f:fs) = do
a <- getFieldValue s f
l <- getFieldValues s fs
return (a :. l)
The paper does other neat things like defining classes for appending
two HList types and for accessing list elements by index (which has to
be encoded as a type-level natural).
--
Frederik Eaton http://ofb.net/~frederik/
|