Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Functors and Monads for People Who Have Read Too Many "Tutorials" (2021) (jerf.org)
1 point by Tomte on Aug 2, 2024 | hide | past | favorite | 4 comments


TBH, it took way too long to explain exactly what a "functor" is, and I find it pretty confusing.

In the section trying to finally define it, it starts off with "Functor is an interface...", and then ends the paragraph with "In Haskell's case, Functor, which is implemented by providing an fmap implementation. For the above examples, that function will:..."

So is it an interface or a function? Is it one and the same in Haskell? I am utterly confused.

If the goal was to explain anything simply, this article fails spectacularly for me.


> So is it an interface or a function? Is it one and the same in Haskell? I am utterly confused.

Functor is an interface. It has one member: a function called fmap. To specify how a type meets the Functor interface you have to define the function fmap for that type.


Thanks: that actually does a better job explaining it in fewer words.


Applicative is n-ary lifting, Functor is a special unary case of Applicative:

    liftA0 :: Applicative f => (a)                -> (f a)
    liftF1 ::     Functor f => (a -> b)           -> (f a -> f b)
    liftA2 :: Applicative f => (a -> b -> c)      -> (f a -> f b -> f c)
    liftA3 :: Applicative f => (a -> b -> c -> d) -> (f a -> f b -> f c -> f d)
    .. where
  liftA0 = pure
  liftF1 = fmap




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: