[Haskell-beginners] Rewriting bits of a data structure

Adrian May adrian.alexander.may at gmail.com
Tue May 21 18:35:35 CEST 2013


Hi All,

I have a lot of ugly code like this:

data Thing = Thing Int Int Int Int Int
rewriteFourth :: Int -> Thing -> Thing
rewriteFourth x (Thing a b c _ e) = Thing a b c x e

Is there a better way?

It was thinking about state monads that reminded me of this junk that I'd
already written a while ago. Maybe it can be done by applying five StateT
transformers, but I'm not entirely sure how to write that, or if there's a
simpler fix.

TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130522/d75fb342/attachment.htm>


More information about the Beginners mailing list