Can someone explain the connection between accessing the value in a monad, and iteration? The author dances around this but I have had dreams thinking about it.
I can't completely formulate the question as I'm confused. But sometimes it seems a monad is just a compilable wrapper around a value such as future or option, and map calls a function on that value. But in the case of a list map performs an iteration.
I've always thought of map and flatMap as iteration functions because they "map over a sequence". But that no longer seems to be the case.
Let’s have a quick random example: I could have my own functor, working on lists, which keeps the elements sorted. If I apply a random function to it, the result has to be also sorted. You can see the problem? my functor will keep it sorted while an externalized loop may or may not keep it sorted, depending on the programmer.
MySortedList (1,2,3) map (rand(_))
will always be sorted, while List (1,2,3) map (rand(_))
is not…
F.map[B] (f : A => B) : F[B]
map[B] (f : A => B) : F[A] => F[B]
F[A].map[B] (f : A => B) : F[B]
On Sep 26, 2016, at 12:21 PM, Jim Newton <jimka...@gmail.com> wrote:Thanks, that helps somewhat. But I don't understand what a functor is. It sounds like a parameterized function which only exists at compiled time and not at runtime, and thus is not first class.
And also, when you say F.map[B] (f : A => B) : F[B], why is there no "A," inside the first brackets? What is special about B which is not special about A in F.map[B] (f : A => B) : F[B] ?