[Haskell-beginners] apply a function to all params of another function

Kees Bleijenberg k.bleijenberg at lijbrandt.nl
Mon May 26 14:46:29 UTC 2014


In have a lot of functions in a program with params that are alle Int's.  
f :: Int -> Int -> Int
g :: Int -> Int -> Int
h :: Int -> Int -> Int -> Int
...
and convertParam :: Int -> Int -- say (+1) 
I want to call functions like f, g and h, but apply convertParam to all
params first.
f2 a b c = f (convertParam a) (convertParam b) (convertParam c)

I tried:
run1p f  conv = \a  -> f (conv a)     		-- for functions with one
param
run2p f  conv = \a b ->  f (conv a) (conv b) 	-- for functions with two
params
.
Can you do this in a more generalized way (using currying?)
Any ideas?

Kees





More information about the Beginners mailing list