For example:
fun example (a:'a list) : list = a
will have a signatures of:
'a list -> 'a list
What if I define it differently but with same content like
fun example (a : ''a list) : list = a
its signature will be:
''a list -> ''a list
What's the difference?
A plain type variable like
'acan be substituted with an arbitrary type. The form''ais a so-called equality type variable, which means that it can only be substituted by types that admit the use of the equality operator=(or<>) on their values.For example, this function:
cannot have type
'a * 'a list -> boolbecause it uses equality onx. It is given the more restrictive type''a * ''a list -> bool.Most types allow equality, but some don't, e.g.,
real,exn, and in particular, any function typet -> u. Composed types like records, tuples, or datatypes admit equality if all their components do.Side remark: Haskell later generalised this concept to its notion of type classes, which allows arbitrary user-defined constraints of this sort on types. Equality type variables are replaced by the
Eqtype class.