2 Hask is not Cartesian closed

is not a terminal object. The Monad identities fail for almost all instances of the Monad class.

Why Hask isn't as nice as you'd thought.

Initial Object

Terminal Object

Sum

Product

Product

Type

data Empty

data()=()

dataEither a b= Left a | Right b

data(a,b)=(,){fst:: a, snd:: b}

data P a b = P {fstP ::!a, sndP ::!b}

Requirement

There is a unique function

u :: Empty -> r

There is a unique function

u :: r ->()

For any functions

f :: a -> r

g :: b -> r

there is a unique function

u ::Either a b -> r

such that:

u . Left = f

u . Right = g

For any functions

f :: r -> a

g :: r -> b

there is a unique function

u :: r ->(a,b)

such that:

fst . u = f

snd . u = g

For any functions

f :: r -> a

g :: r -> b

there is a unique function

u :: r -> P a b

such that:

fstP . u = f

sndP . u = g

Candidate

u1 r =case r of{}

u1 _ =()

u1 (Left a)= f a

u1 (Right b)= g b

u1 r =(f r,g r)

u1 r = P (f r)(g r)

Example failure condition

r ~()

r ~()

r ~()

f _ =()

g _ =()

r ~()

f _ =undefined

g _ =undefined

r ~()

f _ =()

g _ =undefined

Alternative u

u2 _ =()

u2 _ =undefined

u2 _ =()

u2 _ =undefined

Difference

u1 undefined=undefined

u2 undefined=()

u1 _ =()

u2 _ =undefined

u1 undefined=undefined

u2 undefined=()

u1 _ =(undefined,undefined)

u2 _ =undefined

f _ =()

(fstP . u1) _ =undefined

Result

FAIL

FAIL

FAIL

FAIL

FAIL

3 "Platonic" Hask

Because of these difficulties, Haskell developers tend to think in some subset of Haskell where types do not have bottom values. This means that it only includes functions that terminate, and typically only finite values. The corresponding category has the expected initial and terminal objects, sums and products, and instances of Functor and Monad really are endofunctors and monads.