[Haskell-beginners] Trouble with formatting,
Real World Haskell example
Steven Ashley
steven.e.ashley at gmail.com
Sun Nov 23 00:10:24 EST 2008
Hi Robert,
The contents of the do block must be indented at-least as much as
mainWith on the previous line.
For instance:
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
The haskell wikibook has some more detailed information of
http://en.wikibooks.org/wiki/Haskell/Indentation
Regards,
--Steven
2008/11/23 Robert Kosara <rkosara at gmail.com>:
> 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
>
> Regards,
> Robert
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
More information about the Beginners
mailing list