[Haskell-cafe] monad constraint + record update

Cristiano Paris cristiano.paris at gmail.com
Mon Dec 22 15:08:29 EST 2008

On Mon, Dec 22, 2008 at 6:19 PM, Peter Padawitz <peter.padawitz at udo.edu> wrote:
> I'd like to define a monad Set for types in the class Eq. But how can the
> arguments of Set be constrained when Set is defined as an instance of Monad?
> instance Eq a => Monad Set where ... obviously cannot work.

Shouldn't you impose the constraint when defining functions operating
on Set values? I guess that the contraint should be enforced not only
when dealing with monadic code, but also whenever it appears in your

> Is there a standard update function for fields in data types, something that
> OO programmers do with assignments like obj.attr := value ?

Your statement doesn't make much sense in the functional world of Haskell.

There's a record update construct which may resemble the OO data
update operation but it makes a whole new copy of the original value,

foo a = a { attr = value }

which is basically like doing:

foo a = a + 2


More information about the Haskell-Cafe mailing list