<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 26, 2014 at 2:16 PM, Vale Cofer-Shabica <span dir="ltr"><<a href="mailto:vale.cofershabica@gmail.com" target="_blank">vale.cofershabica@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div id=":1df" class="" style="overflow:hidden">However, if I try to use f' or f'', I get parse errors. Three questions:<br>

<br>
* Is there a better way of doing this<br>
* Are stylistic changes to f really called for?<br>
* How can/ought I correct my syntax errors?</div></blockquote></div><div class="gmail_extra"><br></div>if and case are expressions. As such they are not part of the outer "do"'s syntax; you would need a new "do" in each one. This will make more sense if you study how "do" is converted to uses of the (>>) and (>>=) operators.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Additionally you can't just use "s <- getContents" like that, since (a) "s" will go out of scope, abnd (b) with nothing following, it expands to a syntax error ("getContents >>= \s ->" with nothing after the "->"). Since if and case are expressions, you need to produce a result from them and bind it at the top level. So you really want something like:<br>
<br clear="all"><div><span style="font-family:arial,sans-serif;font-size:12px">    f' :: String -> IO ()</span><br style="font-family:arial,sans-serif;font-size:12px"><span style="font-family:arial,sans-serif;font-size:12px">    f' file = do</span><br style="font-family:arial,sans-serif;font-size:12px">
<span style="font-family:arial,sans-serif;font-size:12px">      s <- if file == "-"</span><br style="font-family:arial,sans-serif;font-size:12px"><span style="font-family:arial,sans-serif;font-size:12px">               then getContents</span><br style="font-family:arial,sans-serif;font-size:12px">
<span style="font-family:arial,sans-serif;font-size:12px">               else readFile file</span><br style="font-family:arial,sans-serif;font-size:12px"><span style="font-family:arial,sans-serif;font-size:12px">      putStrLn s</span><br style="font-family:arial,sans-serif;font-size:12px">
</div><div><span style="font-family:arial,sans-serif;font-size:12px"><br></span></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>
<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>