Tillmann Rendel rendel at Mathematik.Uni-Marburg.de
Wed Sep 1 17:28:10 EDT 2010

```michael rice wrote:
> Prelude Data.Either> let m = Just 7
> Prelude Data.Either> :t m
> m :: Maybe Integer

So to create a value of type (Maybe ...), you can use Just.

> Prelude Data.Either> let l = 2:[]
> Prelude Data.Either> :t l
> l :: [Integer]

So to create a value of type [...], you can use (:) and [].

> Prelude Data.Either> let g = getLine
> Prelude Data.Either> :t g
> g :: IO String

So to create a value of type (IO ...), you can use getLine.

> Prelude Data.Either> let e = Right "abc"
> Prelude Data.Either> :t e
> e :: Either a [Char]

So to create a value of type (Either ... ...), you can use Right.

> How can I similarly create an instance of (->) [...] ?

An "instance of (->)" is usually called a function. And functions are
created by lambda abstraction:

Prelude> let f = \x -> x
Prelude> :t f
f :: t -> t

So to create a value of type (... -> ...), you can use \.

Just like Either, -> is a binary type constructor. Just like (Either a
b) is a type, (a -> b) is a type. And very much like you can create
(Either a b) values with Left and Right, you can create (a -> b) values
with \.

Tillmann

PS. After studying how to construct values, it may be instructive to
study how to take them apart. For example, Bool values can be taken
apart by if-then-else expressions. What about Either, IO and -> values?
```