
2009/9/6 Günther Schmidt
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 Record
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 = Record (HCons (LVPair (Label HZero) DRG) (HCons (LVPair (Label (HSucc HZero)) BelegungsTyp) (HCons (LVPair (Label (HSucc (HSucc HZero))) EntgeltBetrag) (HCons (LVPair (Label (HSucc (HSucc (HSucc HZero)))) Zuschläge) (HCons (LVPair (Label (HSucc (HSucc (HSucc (HSucc HZero))))) Abschläge) HNil)))))
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.
Günther
Am 07.09.2009, 02:44 Uhr, schrieb Edward Z. Yang
: 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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Why don't you define your record to be the final set of all the information that you will collect, and just leave some of the fields undefined until you collect all the data? That would work well if you are going to be collecting all of the data pretty much all at once. You could also have a record of Maybe values that started out as all Nothing and became Justs as the data was collected. Maybe I'm misunderstanding your problem, but that's how I would do it. Alex