There is no instance for (Num (Int & # 8594; Int)) arising from the letter `5 '

I have the following function:

f :: (Int -> Int) -> Int
f = undefined

Now I want to call fwith 5(which is wrong):

f 5

Obviously, this should not compile, because it is 5not a function of from Intto Int. So I expect an error message like Couldn't match expected type Int -> Int with Int.

But instead, I get:

No instance for (Num (Int -> Int)) arising from the literal `5'
In the first argument of `f', namely `5'
In the expression: f 5
In an equation for `it': it = f 5

Why did you appear here Num?

+4
source share
1 answer

5has a type of any type in the class Num. These types include Int, Double, Integeretc.

Num. , Num , . . 5 constant-five.

fromInteger 5, 5 Integer. , f 5 f (fromInteger 5), Int -> Int. Num (Int -> Int).

, GHC , 5 ( , , fromInteger). , Num.

+12

Source: https://habr.com/ru/post/1569163/


All Articles