From my lecture, I learn that the type of the expression (n `mod` 2 == 0) is Int -> Bool why it is not Int -> Int -> Bool ?
n `mod` 2 has the type (Int -> Int) and if we write n `mod` 2 in the form g = h(n) then (n `mod` 2 == 0) can be write as g(m) which has the type Int -> Bool
In the end isn't it shall be the type (Int -> Int -> Bool)?

(n `mod` 2 == 0)has as typeBool, indeed, the expression is equivalent to(==) (mod n 2) 0and since(==) :: Eq a => a -> a -> Boolreturns aBoolif it uses two parameters, this thus means that(n `mod` 2 == 0)has as typeBool. This will require that there is variable namednthat is in scope and thatnneed to have as typen :: Integral a => a, so a value of a type that is a member of theIntegraltypeclass. It also means thatmod n 2and0both have to be of the same type, and that type is a member of theEqtypeclass.If you construct a function with
nas parameter, like\n -> nthen it has as typemod2 == 0Integral a => a -> Bool, or you can further specialize that toInt -> Bool, since it is a function that maps a parameternof typeIntegral a => aor specialized asIntto aBool.For the same reason it is not
Int -> Int -> Bool: it takes no parameters, and the(n `mod` 2 == 0)itself is an expression that evaluates to aBool, hence its type isBool. If you would have constructed a function, like\n -> \m -> n `mod` 2 == 0, its type wasIntegral a => a -> (b -> Bool)or less verboseIntegral a => a -> b -> Bool. Heremcan be a value of any type, and its value does not matter for the result of the function. It is thus just an "ad hoc" variable used to make this a function that takes two parameters.The same holds for
n `mod` 2: a more canonical form of this expression ismod n 2, sincemodhas typemod :: Integral a => a -> a -> ais an expression of typeIntegral a => a. This type is the same as the type fornand2. If we make a function withnthe parameter, so\n -> n, then the type of this function ismod2Integral a => a -> a. The type can be specialized toInt -> Int, sinceIntis a member of theIntegraltypeclass.