# Hask

### From HaskellWiki

m (→Hask: newlines) |
|||

Line 15: | Line 15: | ||

! scope="row" | Definition |
! scope="row" | Definition |
||

| There is a unique function |
| There is a unique function |
||

− | <hask>u :: Empty -> r</hask> |
+ | <br /><hask>u :: Empty -> r</hask> |

| There is a unique function |
| There is a unique function |
||

− | <hask>u :: r -> ()</hask> |
+ | <br /><hask>u :: r -> ()</hask> |

| For any functions |
| For any functions |
||

− | <hask>f :: a -> r</hask> |
+ | <br /><hask>f :: a -> r</hask> |

− | <hask>g :: b -> r</hask> |
+ | <br /><hask>g :: b -> r</hask> |

there is a unique function |
there is a unique function |
||

− | <hask>u :: Either a b -> r</hask> |
+ | <br /><hask>u :: Either a b -> r</hask> |

such that: |
such that: |
||

− | <hask>u . Left = f</hask> |
+ | <br /><hask>u . Left = f</hask> |

− | <hask>u . Right = g</hask> |
+ | <br /><hask>u . Right = g</hask> |

| For any functions |
| For any functions |
||

− | <hask>f :: r -> a</hask> |
+ | <br /><hask>f :: r -> a</hask> |

− | <hask>g :: r -> b</hask> |
+ | <br /><hask>g :: r -> b</hask> |

there is a unique function |
there is a unique function |
||

− | <hask>u :: r -> (a,b)</hask> |
+ | <br /><hask>u :: r -> (a,b)</hask> |

such that: |
such that: |
||

− | <hask>fst . u = f</hask> |
+ | <br /><hask>fst . u = f</hask> |

− | <hask>snd . u = g</hask> |
+ | <br /><hask>snd . u = g</hask> |

|- |
|- |
||

! scope="row" | Platonic candidate |
! scope="row" | Platonic candidate |
||

Line 50: | Line 50: | ||

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

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

− | <hask>f _ = ()</hask> |
+ | <br /><hask>f _ = ()</hask> |

− | <hask>g _ = ()</hask> |
+ | <br /><hask>g _ = ()</hask> |

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

− | <hask>f _ = undefined</hask> |
+ | <br /><hask>f _ = undefined</hask> |

− | <hask>g _ = undefined</hask> |
+ | <br /><hask>g _ = undefined</hask> |

|- |
|- |
||

! scope="row" | Alternative u |
! scope="row" | Alternative u |
||

Line 64: | Line 64: | ||

! scope="row" | Difference |
! scope="row" | Difference |
||

| <hask>u1 undefined = undefined</hask> |
| <hask>u1 undefined = undefined</hask> |
||

− | <hask>u2 undefined = ()</hask> |
+ | <br /><hask>u2 undefined = ()</hask> |

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

− | <hask>u2 _ = undefined</hask> |
+ | <br /><hask>u2 _ = undefined</hask> |

| <hask>u1 undefined = undefined</hask> |
| <hask>u1 undefined = undefined</hask> |
||

− | <hask>u2 undefined = ()</hask> |
+ | <br /><hask>u2 undefined = ()</hask> |

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

− | <hask>u2 _ = undefined</hask> |
+ | <br /><hask>u2 _ = undefined</hask> |

|- style="background: red;" |
|- style="background: red;" |
||

! scope="row" | Result |
! scope="row" | Result |

## Revision as of 05:59, 8 August 2012

**Hask** refers to a 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*). The reason for this is that platonic

**Hask****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.

## 1 **Hask**

Actual **Hask**does not have sums, products, or an initial object, and

Initial Object | Terminal Object | Sum | Product | |
---|---|---|---|---|

Definition | 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 |

Platonic candidate | u1 r = case r of {} |
u1 _ = () |
u1 (Left a) = f a u1 (Right b) = g b |
u1 r = (f r,g r) |

Example failure condition | r ~ () |
r ~ () |
r ~ () f _ = () g _ = () |
r ~ () f _ = undefined 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 |

Result | FAIL | FAIL | FAIL | FAIL |

## 2 Platonic **Hask**

Because of these difficulties, Haskell developers tend to think in some subset of Haskell where types do not have bottoms. 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.