2011/9/6 Poprádi Árpád <popradi_ar...@freemail.hu>:
> i have a record with a lot of items used in a state monad.
>
> data BigData = BigData {
>                   data1 :: X
>                 , data2 :: X
>                -- and so on
>                }
>
> updateData1 :: X -> MonadicEnv()
> updateData1 d = do; env <- get; put env {data1 = d}
>
> updateData2 :: X -> MonadicEnv()
> updateData2 d = do; env <- get; put env {data2 = d}
>
> But it's ugly. Always the same, only the record selector has another
> name.
> Is it possible to generalize it?

You can use the fclabels package [1] for this. It makes record labels
first class, and also provides functions to update parts of a record
in the state monad [2]. You would be able to write something like:

updateData1 = puts data1 d

It has a function for modifcation as well, which is even uglier with
regular record syntax.

Erik

[1] http://hackage.haskell.org/package/fclabels
[2] 
http://hackage.haskell.org/packages/archive/fclabels/1.0.4/doc/html/Data-Label-PureM.html#v:puts

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to