I hope the spacing is preserved by my email client; here's a formatting that compiles:
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
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 Haskellimport System.Environment (getArgs)interactWith function inputFile outputFile = doinput <- readFile inputFilewriteFile outputFile (function input)main = mainWith myFunctionwhere mainWith function = doargs <- getArgscase args of[input, output] -> interactWith function input output_ -> putStrLn "Usage: Interact inputFile outputFile"myFunction = idRegards,Robert
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
On Sat, Nov 22, 2008 at 9:53 PM, Robert Kosara <rkosara@gmail.com> wrote:
_______________________________________________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 Haskellimport System.Environment (getArgs)interactWith function inputFile outputFile = doinput <- readFile inputFilewriteFile outputFile (function input)main = mainWith myFunctionwhere mainWith function = doargs <- getArgscase args of[input, output] -> interactWith function input output_ -> putStrLn "Usage: Interact inputFile outputFile"myFunction = idRegards,Robert
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners