MostlyAdequate / mostly-adequate-guide

Mostly adequate guide to FP (in javascript)
Other
23.42k stars 1.87k forks source link

Expound on functor map type signature #62

Closed mikehaertl closed 8 years ago

mikehaertl commented 9 years ago

In chapter 8 I found this type signature:

map :: Functor f => (a -> b) -> f a -> f b

While the introductory chapter on Hindley-Milner was easy to follow, I think it doesn't cover the above signature. The problem is the f a and f b part. What does that mean? f multiplied by a? Or f applied to a? Or something else? Maybe you could elaborate on this a little.

Oh, and by the way, thanks for your impressive work so far. It's a joy to read and I like how concise you present the main principles.

DrBoolean commented 9 years ago

Thanks! Yeah, I'll definitely have to work both type constraints and f a into the signature chapter.

To elaborate here: f a simply means functor with an a in it like Maybe("test") or IO(2).

dmitriz commented 7 years ago

Mathematically, f a should mean the functor f applied to the type a, and the result is the new type. Now replace types by objects and you get the exact maths definition (https://en.wikipedia.org/wiki/Functor)