That's not really how I visualize functors. Let's go back to the function picture:<p><pre><code> --- ---
|a| -- f --> |b|
--- ---
</code></pre>
This is fairly simple--using f, you can go from a to b.<p>Now lets imagine a functor F (with f still being our function):<p><pre><code> --- ---
|a| -- f --> |b|
--- ---
| |
|F|
\ /
V
---- ----
|a'| -- f' --> |b'|
---- ----
</code></pre>
So a functor is just a function at a higher level. A function maps values of one type to values of another type. A functor maps types to other types. In Haskell, types in the Functor class always map types of kind * back onto * , so they're much like functions of type a -> a.<p>The crucial part to notice is that it not only maps between types but it also <i>preserves</i> functions. That is, you get new types corresponding to your old types and new functions corresponding to your old functions.<p>So the list type, for example, maps any type a to [a] and any function (a -> b) to ([a] -> [b]). In a sense, it is like a well-behaved function between types.<p>Coincidentally, thinking of functors like this is how I realized that functors in Haskell are <i>not</i> completely unrelated to functors in OCaml--they're just different reifications of the same mathematical idea.
Site seems to be down, here's a cached copy:
<a href="http://webcache.googleusercontent.com/search?hl=en&client=safari&rls=en&sclient=psy-ab&q=cache%3Anewartisans.com%2F2012%2F08%2Fmonads-in-pictures%2F&oq=cache%3Anewartisans.com%2F2012%2F08%2Fmonads-in-pictures%2F&gs_l=serp.3...60377.63295.1.66800.8.8.0.0.0.1.193.880.0j6.6.0.les%3Bernk_fspiked..0.2...1c.xvj46ZWKaRg&pbx=1" rel="nofollow">http://webcache.googleusercontent.com/search?hl=en&clien...</a>
Decent article, but I have something a little off ... it's an honest question though:<p>What compels people to use words like "grok"? Is comprehend, digest, understand, follow, etc. so insufficient that it necessitates an ugly sounding word meaning emotional absorption to be misappropriated as mental absorption? There's no good tense rules established and it's not widely known outside the domain of nerdom. So I ask, to what ends?
I know nothing about Monads, I know nothing about Haskell except for the fact that it's a functional programming language that has Monads. Yet I still found this really informative... Makes me want to play around with Haskell and see if this article makes it easy to grok how Monads work
from a non-Haskell programmer here. It looks like monads are just a way to call functions in difference context, in js<p><pre><code> map(myObj, someFunc, contextObj)
</code></pre>
Or am I missing something here?