Why Functor class has no return function?

前端 未结 4 1152
予麋鹿
予麋鹿 2020-12-06 00:43

From categorical point of view, functor is pair of two maps (one between objects and another between arrows of categories), following some axioms.

I have assumed, wh

4条回答
  •  借酒劲吻你
    2020-12-06 01:20

    Objects of a category are not the same as objects in a OO programming language (we prefer to call those values in Haskell; what they mean in category theory was discussed here). Rather, the objects of Hask are types. Haskell Functors are endofunctors in Hask, i.e. associate types to types, by the following means:

    Prelude> :k Maybe
    Maybe :: * -> *
    Prelude> :k Int
    Int :: *
    Prelude> :k Maybe Int
    Maybe Int :: *

    OTOH, the arrows of Hask are in fact values, of some function type a -> b. These are associated in the following way:

    fmap :: ( Functor (f ::   t     ->     f t       {- type-level  -} ) )
                 =>         (a->b)  ->  fmap(a->b)   {- value-level -}
                         ≡  (a->b)  ->  (f a->f b)
    

提交回复
热议问题