Haskell/Solutions/Simple input and output

Back to the real world
Back in Type Basics, we said:

You need to open a new window which contains all the options that they can change. Let's look at the type signature for this function:

Opening a window, however, implies not just creating it but also drawing it on the screen. The result, therefore, has to have an  type, just like   has. The real signature should be:

A real example of an  function with such a signature (except for slightly different names) can be found in the HGL package.

Sequencing actions with do
Note that the return type for read is inferred from the type of the expression it is in. 0.5*read("10.0") evaluates to 5.0, as expected. read("10.0") results in an error. In such cases a numeric type must be specified: read "10.0" ::Double, for example.

Controlling Actions
With if-statements:

An alternative using a  block:

Actions under the microscope

 * 1) A let name = value in thing binding has the same type as thing. Because we want the binding to be an IO action, the thing needs to be an IO action, so we need a do keyword.
 * No, not always. Just as in "normal" code, you can omit the do keyword if there's only one IO action following it.
 * 1) The GHCi interpreter is like one big do-block with some extra magic, so that it converts normal expressions to IO-actions. As in any do-block, you can omit the   keyword.