Suppose I want to define a function f
in terms of some other predefined function g
as follows:
f :: Int -> Int -> Int
f 2 b = g b
f _ _ = 1
That is, I want to define the projection, f(2,_) : Int->Int
to be the same as g(_) : Int->Int
. Gladly, Haskell has first class functions, and so definitions like the following squarePlusOne
are valid and standard:
plusOne :: Int -> Int
plusOne i = i+1
square :: Int -> Int
square i = i*i
squarePlusOne :: Int -> Int
squarePlusOne = plusOne . Square
With Haskell's currying (ie. f
takes just one Int
as input and returns an (Int->Int)
typed function), I am surprised I cannot write
f 2 = g
Why not? Or is there some other syntax?