I'm having some trouble getting the InteractWith example from <span class="Apple-style-span" style="font-style: italic;">Real World Haskell</span>'s Chapter 4 to compile. When I use spaces (like below), it says "Interact.hs:10:30: Empty 'do' construct." When I use tabs (4 spaces per tab), I get "Interact.hs:16:13: parse error on input `='." In either case, I don't see the problem. Any help would be greatly appreciated.<div>
<br></div><div>I'm also confused about the formatting of the example in the book (page 72). The last line ("myFunction = id") seems to be indented between the where and the next line, why is that? Is that simply a layout problem? To me, it seems it should be on the same level as the where.</div>
<div><br></div><div>Below is my program:</div><div><br></div><div><div>-- Interact.hs, simple filter in Haskell</div><div><br></div><div>import System.Environment (getArgs)</div><div><br></div><div>interactWith function inputFile outputFile = do</div>
<div> input <- readFile inputFile</div><div> writeFile outputFile (function input)</div><div><br></div><div>main = mainWith myFunction</div><div> where mainWith function = do</div><div> args <- getArgs</div>
<div> case args of</div><div> [input, output] -> interactWith function input output</div><div> _ -> putStrLn "Usage: Interact inputFile outputFile"</div><div><br></div><div> myFunction = id</div>
<div><br></div><div><br></div><div>Regards,</div><div><br></div><div>Robert</div><div><br></div></div>