Michael Saelee

Jan 25, 2019

- Bool - True/False
- Char - Unicode character
- Int - 64 bit signed integer
- Integer - arbitrary-precision integer
- Float - 32-bit IEEE single-precision floating point number
- Double - 64-bit IEEE double-precision floating point number
- Tuple - finite (i.e., of a given arity) sequence of different types

Note, all types have capitalized names!

Note: `:t`

can be used to ask for the type of any expression

A function is a mapping (->) from one type (the domain) to another type (the range).

A function of multiple arguments can be implemented in one of two ways:

- A function that takes a tuple of the requisite types

- A
*curried*function

Note: (->) associates right-to-left, so, equivalent to:

I.e., foo is a function which takes an Int and returns a function which takes a Bool …

Function application (space) associates left-to-right, so:

is equivalent to:

Inspect the types of `id`

, `const`

, `fst`

, and `snd`

. Discuss.

In the type `a -> b`

, `a`

and `b`

are *type variables*. Since they are unqualified, they can be replaced with any type! A function whose type declaration contains a type variable is a *polymorphic* function.

Since an unqualified type variable says nothing about its actual type, you can’t do much with it (why?)

But this means the type of a polymorphic function is usually very helpful in determining what it does!

e.g., what do `id`

, `const`

, `fst`

, `snd`

do?

Inspect the types of `==`

, `+`

, `show`

, `read`

Above, `Num a`

is a *class constraint*, implying that the actual type of type variable `a`

must belong to the *type class* `Num`

.

A type that contains a class constraint is called *overloaded*.

A *class* is a collection of types that support a set of overloaded functions called *methods*. Each type belonging to a given class is called an *instance* of that class.

`:i`

gives us information on both types and classes.

Though Haskell can infer types for us, it is good practice to always explitly declare types for all our functions.