I know Haskell isn’t OO so it isn’t strictly a ‘member variable’.
data Foo = Foo {
bar :: Int,
moo :: Int,
meh :: Int,
yup :: Int
}
modifyBar (Foo b m me y) = (Foo b' m me y)
where b' = 2
This is how my code looks at the moment. The problem is I am now making data types with 16 or more members. When I need to modify a single member it results in very verbose code. Is there a way around this?
This syntax will copy
foo, and then modify thebarfield of that copy to 2. This could be naturally extended to more fields, so you don’t need to write thatmodifyBarfunction at all.(See http://book.realworldhaskell.org/read/code-case-study-parsing-a-binary-data-format.html#id625467)