Difference between revisions of "Hask"
(→Hask: stretch out table) 
(→Hask) 

Line 23:  Line 23:  
there is a unique function 
there is a unique function 

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

such that: 
such that: 

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

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

 For any functions 
 For any functions 

Line 33:  Line 33:  
there is a unique function 
there is a unique function 

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

such that: 
such that: 

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

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

 
 
Revision as of 18:29, 17 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 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
Actual Hask does not have sums, products, or an initial object, and ()
is not a terminal object. The Monad identities fail for almost all instances of the Monad class.
Initial Object  Terminal Object  Sum  Product  

Definition  There is a unique function

There is a unique function

For any functions
there is a unique function
such that:

For any functions
there is a unique function
such that:

Platonic candidate  u1 r = case r of {}

u1 _ = ()

u1 (Left a) = f a

u1 r = (f r,g r)

Example failure condition  r ~ ()

r ~ ()

r ~ ()

r ~ ()

Alternative u  u2 _ = ()

u2 _ = undefined

u2 _ = ()

u2 _ = undefined

Difference  u1 undefined = undefined

u1 _ = ()

u1 undefined = undefined

u1 _ = (undefined,undefined)

Result  FAIL  FAIL  FAIL  FAIL 
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.