Darryn Reid wrote: > Martijn van Steenbergen wrote: >> >> A small remark: I prefer using applicative notation for this: >> >>> go Next (Single x t1) = Single x <$> rewrite f t1 >>> go Next (Fork t1 t2 ) = Fork <$> rewrite f t1 <*> rewrite f t2 >> > > Thanks for your comment and advice. Could you explain a little further > your thinking? Specifically, what advantage do you find in the > applicative notation, and when would you advise using it and when would > you advise not using it?
The applicative notation is more general since it also applies to applicative functors http://www.cs.nott.ac.uk/~ctm/IdiomLite.pdf It's main advantage over the liftM family is that it can be used with any number of arguments liftM f m = f <$> m liftM2 f m n = f <$> m <*> n liftM3 f m n o = f <$> m <*> n <*> o etc. and that's why I prefer it as well. It's very similar to function application, too, just think of <*> as a replacement for the empty space that separates function arguments. The only drawback is probably that you have to import Control.Applicative In fact, it doesn't actually work for monads, I think you have to wrap it in a newtype. :D The same effect can be achieved with `ap` , though: liftM3 f m n p = return f `ap` m `ap` n `ap` o Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe