'''Hask''' refers to a [[Category theory|category]] with types as objects and functions between them as morphisms. However, its use is ambiguous. Sometimes it refers to Haskell (''actual '''Hask'''''), and sometimes it refers to some subset of Haskell where no values are bottom and all functions terminate (''platonic '''Hask'''''). The reason for this is that platonic '''Hask''' has lots of nice properties that actual '''Hask''' does not, and is thus easier to reason in. There is a faithful functor from platonic '''Hask''' to actual '''Hask''' allowing programmers to think in the former to write code in the latter.

+

'''Hask''' is the [[Category theory|category]] of Haskell types and functions.

−

== Definition ==

+

The objects of '''Hask''' are Haskell types, and the morphisms from objects <hask>A</hask> to <hask>B</hask> are Haskell functions of type <hask>A -> B</hask>. The identity morphism for object <hask>A</hask> is <hask>id :: A -> A</hask>, and the composition of morphisms <hask>f</hask> and <hask>g</hask> is <hask>f . g = \x -> f (g x)</hask>.

−

+

−

The objects of '''Hask''' are Haskell types, and the morphisms from objects <hask>A</hask> to <hask>B</hask> are Haskell functions of type <hask>A -> B</hask>. The identity morphism for object <hask>A</hask> is <hask>id :: A</hask>, and the composition of morphisms <hask>f</hask> and <hask>g</hask> is <hask>f . g = \x -> f (g x)</hask>.

+

== Is '''Hask''' even a category? ==

== Is '''Hask''' even a category? ==

Line 82:

Line 80:

<br /><hask>sndP . u = g</hask>

<br /><hask>sndP . u = g</hask>

|-

|-

−

! scope="row" | Platonic candidate

+

! scope="row" | Candidate

| <hask>u1 r = case r of {}</hask>

| <hask>u1 r = case r of {}</hask>

| <hask>u1 _ = ()</hask>

| <hask>u1 _ = ()</hask>

Line 100:

Line 98:

<br /><hask>g _ = undefined</hask>

<br /><hask>g _ = undefined</hask>

| <hask>r ~ ()</hask>

| <hask>r ~ ()</hask>

−

<br /><hask>f _ = undefined</hask>

+

<br /><hask>f _ = ()</hask>

−

<br /><hask>g _ = ()</hask>

+

<br /><hask>g _ = undefined</hask>

|-

|-

! scope="row" | Alternative u

! scope="row" | Alternative u

Line 119:

Line 117:

| <hask>u1 _ = (undefined,undefined)</hask>

| <hask>u1 _ = (undefined,undefined)</hask>

<br /><hask>u2 _ = undefined</hask>

<br /><hask>u2 _ = undefined</hask>

−

| <hask>g _ = ()</hask>

+

| <hask>f _ = ()</hask>

<br /><hask>(fstP . u1) _ = undefined</hask>

<br /><hask>(fstP . u1) _ = undefined</hask>

|- style="background: red;"

|- style="background: red;"

Line 132:

Line 130:

== "Platonic" '''Hask''' ==

== "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. Instances of Functor and Monad really are endofunctors and monads.

+

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.

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.