Even
f :: Bool -> Int -> (a -> Int) -> Int fxyz = if x then y + y else (zy) + (zy)
there will be no typecheck (as mentioned in the comments) and will generate the same error, because Haskell indicates the least common types of expressions, and your type is more general than the intended one. Like the "Gentle Introduction to Haskell," adds
The basic type of an expression or function is the least general type, which intuitively "contains all instances of the expression."
If you specify the type explicitly, Haskell assumes that you did this for some reason, and insists that the inferred type matches this type.
For the expression above, the type deduced is (Num t) => Bool -> t -> (t -> t) -> t , so when matching the types, it sees that you gave Int for y , and the type z becomes (Int -> Int) Which is less common than (a -> Int) . But you insisted on having a (not Int ) - a hard-type variable. In other words, your function f can only accept functions of type Int -> Int , but you insist that any function :: a -> Int , including :: String -> Int , etc. can be provided to it. (As @augustsson points out in the comments), your declared type is too wide.
Similarly, if you had only one (zx) , it would correspond to the given type x and come to a narrower than the declared type (Bool -> Int) for the function z . And again complain about a hard variable of type.
In fact, you declared type (Num t) => Bool -> t -> (t1 -> t) -> t , but actually it is (Num t) => Bool -> t -> (t -> t) -> t . This is a different type.
source share