Varieties of laziness: clojure reducers, scala views and closure functors

This is very cool.

(Thanks to David Nolen, who pointed out errors in the original.)

I hadn't realized that the standard higher order sequence functions compose in a manner that requires quite a bit of run-time machinery. For example nested map calls will cause a separate lazy sequence to be instantiated at each level of nesting, with each level "pulling" results from the next innermost as needed. The function calls are thus temporally interleaved, but the functions are not actually composed. We can see this happening by adding some printlns to some unary functions and then running a nested …

more ...


Three Laws of Functor Confusion

There's a conspiracy to prevent you from understanding functors, and the here are some of the tools used to keep you in the dark:

  1. In explanations about functional programming, authors blithely use f to mean either a function or an object for which there's a functor, e.g.
  f      :: (a -> b -> c)
  fmap   :: Functor f => (d -> e) -> f d -> f e
  fmap f :: Functor f =>             f a -> f (b -> c)    -- Identify d with a, and e with (b -> c)
  1. The word functor sometimes means a mapping between categories and other times means an object in a category for which such …
more ...