Re:Modern Functional Programming: The Onion Architecture
by lmm on Friday September 30, 2016 @03:44AM
(#12611030)
The trouble is that applicative doesn't let you use the result of one effect to compute the next effect. (Indeed sometimes there is no there there: Const is a valid applicative). Monads have bind, but that's a little too powerful to implement efficiently. Like I said, I suspect ArrowChoice or the like might be the missing intermediate construct.
applicative is for specific elements of the structure. It's totally reasonable to want access to nearby values, but that requires being a little bit tricky. You could do something like a window of averages
and then do your fmap across that For access to prior values, you need something that looks a lot more like a fold. In that kind of case, i'd point at traversable. which would gather up the sums, [1, 3, 6, 10, 15]of course, accumulator can be as fancy as you want, hashmap, set, tree, or whatever. If you can formulate a dynamic programming solution, there's generally a way to stuff that into traversable.
This is sort of off the top of my head and my haskell is a bit rusty, so this probably won't compile. But i think it captures the essence.