[Applying reviewer comments to ch 7 John Goerzen **20080108065304] { hunk ./en/ch07-io.xml 14 - with and important to understand. I/O is the one area where the rest of - Haskell's lack of side effects doesn't always apply. Haskell provides - nice tools for separating I/O from computation, which helps isolate code - that could introduce side effects. + with and important to understand. Normally, Haskell has no side + effects. I/O is the one exception to that rule, and it's + important to understand how it fits in. + Haskell provides helpful + tools for separating I/O from computation, which helps isolate code + that could introduce side effects. It also permits compilers to + automatically + introduce optimizations and parallelism. hunk ./en/ch07-io.xml 36 - Let's get started with I/O by looking at a program that looks - surprisingly similar to I/O in other languages. + Let's get started with I/O in Haskell by looking at a program that looks + surprisingly similar to I/O in other languages such as C or Perl. hunk ./en/ch07-io.xml 58 - I/O action to a name. + I/O action to a name. hunk ./en/ch07-io.xml 65 - - &do; is a convenient way to define a sequence of actions. As you'll - see later, there are other ways. When you use &do; in this way, - indentation is significant; make sure you line up your actions - properly. - - - You only need to use &do; if you have more than one action that you need - to perform. The return value of a &do; block is the return value - of the last action executed. For a complete description of &do; - syntax, see . - hunk ./en/ch07-io.xml 73 - is your key to knowing that they may have side-effects or return - different values at different times. The type of &putStrLn; looks like - a function. It takes a parameter&emdash;a &String;&emdash;and returns an + is your key to knowing that they may have side-effects, or that + they may return different values even when called with the same + arguments, or both. The type of &putStrLn; looks like + a function. It takes a parameter of type &String; and returns + value of type hunk ./en/ch07-io.xml 87 - the middle of another I/O action, it will be executed. The + the middle of another I/O action, the + writefoo action will be executed when its + parent action is executed. The hunk ./en/ch07-io.xml 91 - no return value to speak of from &putStrLn;. Let's look at that with + no return value to speak of from &putStrLn;. This is similar to + void in Java or C. Strictly speaking, + () is a 0-element tuple; see for details. + + + Let's look at this with hunk ./en/ch07-io.xml 103 - value from &putStrLn;. Rather, it's the result of &putStrLn; actually + value from &putStrLn;. Rather, it's the side effect of &putStrLn; actually hunk ./en/ch07-io.xml 106 + + Notice one other thing: &ghci; actually executed + writefoo. This means that, when given an I/O + action, &ghci; will perform it for you on the spot. + + + What Is An Action? + + Actions: + + + Have the type IO t + + Are first-class values in Haskell + + + Produce an effect when + performed, but not when + evaluated. That is, they only produce an + effect when called by something else in an I/O context. + + + Performing an action of type IO + t may perform I/O and will ultimately deliver a + result of type t + + + hunk ./en/ch07-io.xml 152 + + + &do; is a convenient way to define a sequence of actions. As you'll + see later, there are other ways. When you use &do; in this way, + indentation is significant; make sure you line up your actions + properly. + + + You only need to use &do; if you have more than one action that you need + to perform. The value of a &do; block is the value + of the last action executed. For a complete description of &do; + syntax, see . + + + }