3 ms·
Don't forget currying. Actually, in Haskell, function have exactly one argument. If you need more, just return a function. -- appears to have 2 arguments
by loup-vaillant 15y ago
Don't forget currying. Actually, in Haskell, function have exactly one argument. If you need more, just return a function.
-- appears to have 2 arguments
foo :: Int -> Int -> Int
foo x y = x + (y * y)
-- equivalent definition
foo :: Int -> (Int -> Int)
foo x = \y -> x + (y * y)
-- or even more consistently
foo :: Int -> (Int -> Int)
foo = \x -> (\y -> x + (y * y))
Thinking this way is more useful in the long run: it makes partial application more natural.
bar :: Int -> List Int -> List Int
Bar = map (foo 42)