Skip to main content

Type Variables

Intro

> import Data.Array

> :t singleton
forall (a :: Type). a -> Array a

The a here is a type variable, means that a can be of any type.

Polymorphic Functions

Functions that have type variables are called polymorphic functions, which allow us to easily write very general functions if they don't use any specific behavior of the types in them.
The following is an example which does not have type variables in function definition, so it is not a polymorphic function.

sayHello:: String -> String
sayHello name = "Hello, " <> name