[Haskell-cafe] Field updates in a state monad
Michael Roth
mroth at nessie.de
Thu Jan 10 10:01:54 EST 2008
Hello list,
still playing with monads and states, I have the following question:
Given:
import Control.Monad.State.Lazy
data MyData = MyData { content :: String }
foobar :: State MyData String
foobar = do
gets content
Ok, that looks nice and tidy. But:
foobar2 :: State MyData ()
foobar2 = do
modify $ \x -> x { content = "hello haskell"}
...looks not so nice.
Exists there a way to write this cleaner without writing countless
"set_xyz" helper functions?
Michael
More information about the Haskell-Cafe
mailing list