What is the categorical basis of the requirement that the Haskell id function return the same value as the value?

How is everything right?

  • In a category, Haskobjects are Haskell types, and Morphisms are Haskell functions. Values ​​do not matter in Hask.
  • An identity morphism is defined as an arrow starting at an object Aand ending at the same object A.
  • The Role of Identity Morphism is played by the Haskell function id.
  • The value returned by the Haskell function idmust be identical to the value of the argument passed.

If an identical morphism is defined in category theory as an arrow from an object A back to the same object A, is not that description that is satisfied by any Haskell type function f :: A -> A?

There is another question , the answers to which may also be affected by this topic, but they seem to consider the level of knowledge of category theory, unfortunately, I do not.

I think this is a very simple entry-level question. So can anyone give an answer using only language, symbols and conditional constructions that a beginner can understand?

+4
source share
3 answers

id . A Hask A -> A, A -> A; .

, / . idA - A, B f :: A -> B, f . idA , f, C g :: C -> A, ifA . g , g.

, A -> A , . (+1) :: Integer -> Integer Integer (*2) :: Integer -> Integer. , , (*2) . (+1), (+1) . (*2), (*2) , - , , .

. Haskell. ; , , , .

, - , , , ( , Hask), . A B ( , ). " ".

, idA - A -> A. , , , " " ( ).

Hask, , , " "; , . , :

f . id = f
id . f = f

, , - , , ( x , badId x x), , id!

(badId . id) x
badId (id x)
badId x

badId x x, , badId . id id ( id x = x). , badId .

+6

, .

id . f = f
g . id = g

f,g . , id - A -> A, .

, Hask , a :: A

id . (const a) = const a

,

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

,

id a = a

, id , .

+12

, Hask , , ,

  • Hask Haskell, - Haskell. Hask.

. Hask , - , Hask.

f g A B Hask , f, g :: A -> B , , a :: A f a g a . , , , , (, a :: A), Hask.

Hask - , !

A priori, values ​​of a non-functional type are not displayed explicitly in the inventory (objects, morphisms, identities, composition rules, unitary and associative properties), which include the Hask category. But in fact, the value a :: Acan be encoded in Hask as a morphism const a :: () -> A, and different values a :: Acorrespond to different morphisms from () to A. This is a fact used in chi calculations, showing that we have no other choice for the identity function on object A in Hask, except for a friend id :: A -> A; id a = a.

+3
source

All Articles