Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the category-theoretical basis for the requirement that the Haskell "id" function must return the same value as passed in?

How can the following all be true?

  1. In the Hask category, the Objects are Haskell types and the Morphisms are Haskell functions. Values play no role in Hask.
  2. The identity Morphism is defined as an arrow originating at an Object A and terminating at the same Object A.
  3. The role of the identity Morphism is played by the Haskell id function.
  4. The value returned from the Haskell id function must be identical to the value of the argument passed in.

If the identity morphism is defined in category theory as an arrow from an Object A back to the same Object A, isn't that description satisfied by any and every Haskell function of type f :: A -> A ?

There is another question whose answers might also perhaps cover this topic, but they seem to assume a level of familiarity with category theory that I unfortunately do not possess.

This seems to me a very basic beginner-level question. So can someone supply an answer using only language, symbols and notional constructs that a beginner can understand?

like image 223
nclark Avatar asked Nov 29 '22 10:11

nclark


1 Answers

I'm not sure I really understood the point of your question.

But identity in categories must satisfy

id . f = f
g . id = g

for any f,g of the correct types. So id is not just any random function A -> A, it is the one satisfying the requirements above.

Note that, in Hask, we have that for any value a :: A

id . (const a) = const a

hence

id (const a ()) = const a ()

hence

id a = a

So id is really what we expect.

like image 105
chi Avatar answered Dec 19 '22 08:12

chi