>    *How do you rewrite your code to improve it?*
>

Edward Kmett just introduced one in another thread. Simplifying, it would be
this:

For all x, y, f:

do { x' <- x ; y' <- y ; return (f x' y') }
-->
f <$> x <*> y

This is a great example, because (1) it reduces clutter and "temporary"
names and (2) requires significant background knowledge on monads and
idioms. We can also generalize this to functions f with increasing arity (f
<$> x <*> y <*> z, etc.). Beginners would not get this, but once you know
this rule, it can greatly improve your coding style. Similarly with liftM2,
liftM3, etc. as mentioned by Stephen.

Any other useful tidbits to share?

Sean
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to