[Haskell-beginners] Trouble with formatting, Real World Haskell example

Robert Kosara rkosara at gmail.com
Sat Nov 22 21:53:37 EST 2008

I'm having some trouble getting the InteractWith example from Real World
Haskell'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.
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.

Below is my program:

-- Interact.hs, simple filter in Haskell

import System.Environment (getArgs)

interactWith function inputFile outputFile = do
    input <- readFile inputFile
    writeFile outputFile (function input)

main = mainWith myFunction
    where mainWith function = do
        args <- getArgs
        case args of
            [input, output] -> interactWith function input output
            _ -> putStrLn "Usage: Interact inputFile outputFile"

        myFunction = id


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081122/e2f2318b/attachment.htm

More information about the Beginners mailing list