[Haskell-cafe] How can i safely change the value of specified key ?

minh thu noteed at gmail.com
Thu Oct 22 05:49:07 EDT 2009


2009/10/22 zaxis <z_axis at 163.com>:
>
>>>replace k v xs = (k,v) : filter ((/=v) . fst) xs
> Great !  thanks you very much

I'm not sure why you're so much happy:

Assume some function defined as follow:

foo a b c = e x y z a b c
  where x = some constant
            y = some other constant
            z = some other constant

'e' means just that the complete body of the function foo involves x,
y, z, a, b and c. Generalizing foo to let the caller choose the values
of x, y, z is just

foo a b c x y z = e x y z a b c
  -- the where is unneeded

In fact, this is what functions are made for: generalizing a given
expression so that part of the expression can be given in arguements.

E.g. turning

e a b

into

f a = e a b

Cheers,
Thu


More information about the Haskell-Cafe mailing list