2007-07-23

Haskell : Record update is not first class

Gradually, I continue to study Haskell. During the try to avoid the trouble Record update is not first class looked into the library HList. Damn, it's a little bit verbose.

What for? To have two functions on entry: String->Maybe Setter и String->Maybe Getter, and hence further everything would be beautiful and safety.

Update 24.07.2007 Damn, it could be more easy

The problem of elegant modeling a state with neither more nor less than 10 fields:


data Slots = Slots {
slot1 :: SlotData
slot2 :: SlotData
slot3 :: SlotData
....
}

and the understanding of аn outer world is done by:

mkGetter n | n == 1 = slot1
| n == 2 = slot2
...

mkSetter n | n == 1 = \s v -> s{slot1=v}
| n == 2 = \s v -> s{slot2=v}
...

Though of course if it could be done without lambdas it would be more convenient.

No comments:

Post a Comment