<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Jun 10, 2015 at 10:50 AM Mike Houghton <<a href="mailto:mike_k_houghton@yahoo.co.uk">mike_k_houghton@yahoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The IO string has already been  supplied - maybe via keyboard input - <br></blockquote><div><br></div><div>A value of type IO String has been provided, but a value of type IO String <b>is not a string.</b> In much the same way that `ls` is not a list of files, but rather a recipe for retrieving a list of files, a value of type IO String is a not a String but a recipe for performing IO that will retrieve a String once it is executed. It is important to remember is that <b>evaluating an IO action does not execute it</b>. Only the runtime system can do that, and the only IO action the runtime system executes is main (which can, of course, be composed of many other IO actions by using, e.g., the Monad interface).</div><div><br></div><div>You can't write a function of type IO String -> String that "retrieves" the string because there is no string to retrieve. There is only a recipe that must be <b>executed</b> and that execution must stay within the IO context.</div><div><br></div><div>(It is possible to write this function using unsafePerformIO precisely because unsafePerformIO instructs the runtime to ignore its usual safety mechanisms (that ensure that IO actions can be used with in a safe, pure, and referentially transparent way) and force the execution of the IO action as part of its evalulation and, as the name suggests, this is unsafe for a number of reasons and should only be used when the programmer is willing to take on the obligation to prove that they are using it in safe way.)</div></div></div>