[Haskell-cafe] Re: HList and Type signatures / synonyms

Günther Schmidt gue.schmidt at web.de
Sun Sep 6 21:38:28 EDT 2009

Hi Edward,

I suppose you're right, I could have made this a little more detailed.

I keep reading in and processing data in an accumulating way, ie. lets say  
I have a DB table (don't take this literally please, just an example),  
into in-memory records of type

data MyRecord = MyRecord {
	name :: String,
	birthDate :: LocalDate}

in a second step I read in Gender information so now I'd need an extended  

data MyRecord = MyRecord {
	name :: String,
	birthDate :: LocalDate,
	gender :: Gender }

and so on for another 12 times.

In other words I need to extend the record.

I had been using tuples, ie:

	(String, LocalDate) -> Gender -> (String, LocalDate, Gender)

but after 6 or so *extensions* things get a tad messy.

Anyway this is where HList really shines, but it is a bit akward when you  
want to state the type of an HList record, ie.

type Entg =
      (LVPair (Label HZero) DRG)
       (LVPair (Label (HSucc HZero)) BelegungsTyp)
        (LVPair (Label (HSucc (HSucc HZero))) EntgeltBetrag)
         (LVPair (Label (HSucc (HSucc (HSucc HZero)))) Zuschläge)
          (LVPair (Label (HSucc (HSucc (HSucc (HSucc HZero))))) Abschläge)

which happens to be my actual stage 1 data type (Entg), one that has 5  
"fields" initial and in several distinct steps 8 more are *added*.

So I wonder if there is a more simple way to do this, ie to *extend* the  
*type* signatures of extend records without such a lot of typing.


Am 07.09.2009, 02:44 Uhr, schrieb Edward Z. Yang <ezyang at mit.edu>:

> Excerpts from Günther Schmidt's message of Sun Sep 06 19:40:05 -0400  
> 2009:
>> I keep accumulating values and right now use plain tuples for that. I  
>> end
>> up with a 12 element tuple and things are a bit messy.
> Hi, you may want to consider using the Writer monad. [1]
>> I'd like to use extensible Records from HList instead, thing is I'd like
>> to keep putting type signatures in my code. As it turns out that seems  
>> to
>> be where it gets messy with HList.
> Perhaps more precisely explaining your problem domain would be useful.
> Cheers,
> Edward
> [1] http://www.haskell.org/all_about_monads/html/writermonad.html

More information about the Haskell-Cafe mailing list