klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Type variable #29

Open klequis opened 2 years ago

klequis commented 2 years ago
  1. A type variable is a way to refer to an unspecified type or set of types in Haskell type signatures. Type variables ordinarily will be equal to themselves throughout a type signature. Let us consider some examples:
    id :: a -> a

    The only type variable, a, occurs twice, once as an argument, once as a result. The type variable is parametrically polymorphic and could be strictly anything.

(+) :: Num a => a -> a -> a

Only one type variable named a, again. a is constrained to requiring an instance of Num. Two arguments of the same type a and one result.

Type variables only appear in type signatures. (that may seem obvious)

  1. A type variable is a variable used in a type signatures such as a in f :: a -> a.
  2. A type variable is a lower case letter such as a used in a type signature.
  3. Type variables are literally variables for types.