[ch07 return coverage and tweaks John Goerzen **20071011071551] { hunk ./en/ch07-io.xml 240 - computation, you must use &return; to wrap it in &IO;. + computation, you must use &return; to wrap it in &IO;. For more + details on &return;, see . hunk ./en/ch07-io.xml 967 - The call to printitall; finally executes all those actions. Actually, + The call to printitall finally executes all those actions. Actually, hunk ./en/ch07-io.xml 1054 + + The True Nature of Return + + Earlier in this chapter, we mentioned that &return; is probably not + what it looks like. Many languages have a keyword named &return; + that aborts execution of a function immediately and returns a value + to the caller. + + + The Haskell &return; function is quite different. In Haskell, + &return; is used to wrap data in a monad. When speaking about I/O, + &return; is used to take pure data and bring it into the IO monad. + + + Now, why would we want to do that? Remember that anything whose + result depends on I/O must be within the IO monad. So if we are + writing a function that performs I/O, then a pure computation, we + will need to use &return; to make this pure computation the proper + return value of the the function. Otherwise, a type error would + occur. Here's an example: + + + + hunk ./examples/ch07/actions.hs 2 --- ch06/actions.hs +-- ch07/actions.hs hunk ./examples/ch07/actions2.hs 2 --- ch06/actions2.hs +-- ch07/actions2.hs hunk ./examples/ch07/basicio-nodo.hs 2 --- ch06/basicio-nodo.hs +-- ch07/basicio-nodo.hs hunk ./examples/ch07/basicio.hs 2 --- ch06/basicio.hs +-- ch07/basicio.hs hunk ./examples/ch07/callingpure.hs 2 --- ch06/callingpure.hs +-- ch07/callingpure.hs hunk ./examples/ch07/filter.hs 2 --- ch06/filter.hs +-- ch07/filter.hs hunk ./examples/ch07/tempfile.hs 2 --- ch06/tempfile.hs +-- ch07/tempfile.hs hunk ./examples/ch07/toupper-imp.hs 2 --- ch06/toupper-imp.hs +-- ch07/toupper-imp.hs hunk ./examples/ch07/toupper-lazy1.hs 2 --- ch06/toupper-lazy1.hs +-- ch07/toupper-lazy1.hs hunk ./examples/ch07/toupper-lazy2.hs 2 --- ch06/toupper-lazy2.hs +-- ch07/toupper-lazy2.hs hunk ./examples/ch07/toupper-lazy3.hs 2 --- ch06/toupper-lazy3.hs +-- ch07/toupper-lazy3.hs hunk ./examples/ch07/toupper-lazy4.hs 2 --- ch06/toupper-lazy4.hs +-- ch07/toupper-lazy4.hs hunk ./examples/ch07/toupper-lazy5.hs 2 --- ch06/toupper-lazy5.hs +-- ch07/toupper-lazy5.hs hunk ./examples/ch07/toupper-lazy6.hs 2 --- ch06/toupper-lazy6.hs +-- ch07/toupper-lazy6.hs }