I am trying to understand the Eq class and while I was reading a chapter about the types in Haskell I faced the following question:
"Explain why is not feasible in general for function types to be instances of the Eq class."
I tried to understand by checking the type of the (==)
function.
:t (==)
(==) :: Eq a => a -> a -> Bool
So a
is instance of Eq
class, but this doesn't show that the (==) function is instance of the Eq class, does it? For me, seems that the two arguments of the function == are instances of the type Eq.
equal x1 x2 = x1 == x2
Is actually equivalent to (==).
My understanding is that, is not feasible always (my above example is feasible) for function types to be instances of the Eq class because they have to have the same number of arguments (two) and return the same type (Bool).
Although I am not sure if that is the case. Is not crystal clear what is meant for a function type to be an instance of a class.