I can’t get it. Why do we even need this? I mean, if I use the same type parameter, I think that means they must be of the same type.
I heard that this can help the compiler avoid an infinite loop. Can someone tell me more details about this?
After all, are there any “patterns and methods” that we must adhere to in using functional dependencies in Real World Haskell?
[Follow-up question]
class Extract container element where
extract :: container -> element
instance Extract (a,b) a where
extract (x,_) = x
In the above code, I used the same variable of type 'a' for the container and element, I think that the compiler can thus conclude that these two types are the same type.
But when I tried this code in GHCi, I got the following feedback:
*Main> extract('x',3)
<interactive>:1:0:
No instance for (Extract (Char, t) element)
arising from a use of `extract' at <interactive>:1:0-13
Possible fix:
add an instance declaration for (Extract (Char, t) element)
In the expression: extract ('x', 3)
In the definition of `it': it = extract ('x', 3)
"Char", "element"?