[Haskell-cafe] why are applicative functors (often) faster than monads? (WAS Google Summer of Code - Lock-free data structures)

Ben midfield at gmail.com
Sat Apr 21 02:29:34 CEST 2012


the sequencing matters for applicative functors.  from McBride and Patterson [1]:

"The idea is that 'pure' embeds pure computations into the pure fragment of an effectful world -- the resulting computations may thus be shunted around freely, as long as the order of the genuinely effectful computations is preserved."

it is interesting to note that sequencing only matters a little for k-CAS : you just have to read before you write, but you can do the reads and writes in any order (as long as it is ultimately atomic.)

b

[1] McBride C, Patterson R. "Applicative programming with effects" Journal of Functional Programming 18:1 (2008), pages 1-13.

On Apr 20, 2012, at 4:41 PM, KC wrote:

> Sorry, I thought you or someone was asking why are Applicative Functors faster in general than Monads.
> 
> Functional programming is structured function calling to achieve a result where the functions can be evaluated in an unspecified order; I thought Applicative Functors had the same unspecified evaluation order; whereas, Monads could carry some sequencing of computations which has the extra overhead of continuation passing.
> 
> Do I have that correct?
> 
> 
> On Fri, Apr 20, 2012 at 4:05 PM, Ben <midfield at gmail.com> wrote:
> i'm not sure what your email is pointing at.  if it is unclear, i understand the difference between applicative and monadic.  i suppose the easy answer to why applicative can be faster than monadic is that you can give a more specialized instance declaration.  i was just wondering if there was a way to make a monad recognize when it is being used applicatively, but that is probably hard in general.
> 
> b
> 
> On Apr 20, 2012, at 2:54 PM, KC wrote:
> 
> > Think of the differences (and similarities) of Applicative Functors and Monads and the extra context that monads carry around.
> >
> >
> > --
> > --
> > Regards,
> > KC
> 
> 
> 
> 
> -- 
> --
> Regards,
> KC




More information about the Haskell-Cafe mailing list