[Haskell-cafe] Is there a null statement that does nothing?

Curt Sampson cjs at starling-software.com
Sun Oct 25 00:08:00 EDT 2009


On 2009-10-21 18:27 -0700 (Wed), michael rice wrote:

> Those nested IF/THEN/ELSEs are real killers. I kind of use them to
> sort out my thoughts, then end up with a nested mess. The restructuring
> to WHENs went smoothly and looks a lot cleaner besides.

Indeed. Monadic control flow is one of the basic keys to being able
to write nice code in Haskell; it's the moral equivalant of using
polymorphism rather than than "case" or "switch" in OO languages. (Well,
some would disagree, but that gets into the whole OO vs. functional
debate.)

You'll probably want to spend some time with one of the zillion monad
tutorials at some point (I like "All About Monads") to learn more about
these things.

BTW, look up the source code for "when". :-)

  http://haskell.org/ghc/docs/latest/html/libraries/base/src/Control-Monad.html#when

cjs
-- 
Curt Sampson       <cjs at starling-software.com>        +81 90 7737 2974
           Functional programming in all senses of the word:
                   http://www.starling-software.com


More information about the Haskell-Cafe mailing list