I am currently trying to wrap my head around typeclasses and instances and I don\'t quite understand the point of them yet. I have two questions on the matter so far:
<
This only answers question 1 (directly, at least).
The type signature f :: a -> a -> Bool
is shorthand for f :: forall a. a -> a -> Bool
. f
would not truly work for all types a
if it only works for a
s that have (==)
defined. This restriction to types that have (==)
is expressed using the constraint (Eq a)
in f :: forall a. (Eq a) => a -> a -> Bool
.
"For all"/universal quantification is at the core of Haskell's (parametric) polymorphism and, among other things, provides the powerful and important properties of parametricity.