[Haskell-cafe] Is there any way to parametrize a value update using record syntax?

Poprádi Árpád popradi_arpad at freemail.hu
Tue Sep 6 21:47:57 CEST 2011


Hi all,

i have a record with a lot of items used in a state monad.

data BigData = BigData {
                   data1 :: X
                 , data2 :: X
		-- and so on
                }

type MonadicEnv a = State BigData a

I updates the fields in the computation with such functions:



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?


Thanks,
Árpád






More information about the Haskell-Cafe mailing list