Generating "setMember" functions for record structures

Christian Maeder maeder at tzi.de
Tue Sep 23 16:38:16 EDT 2003


>>setFoo        :: State -> [Int] -> State
>>setFoo st x    = State { foo = x
>>                       , bar = bar st
>>                       }
> 
> 
>>setBar        :: State -> [String] -> State
>>setBar st x    = State { foo = foo st
>>                       , bar = x
>>                       }

It should be sufficient to just write:

setFoo st x   = st { foo = x }

setBar st x   = st { bar = x }

This creates a new State (out of "st") with an updated field entry 
without mentioning the other fields.

Christian




More information about the Haskell-Cafe mailing list