When I compile below code in Haskell, I get following error:
Error: parse error on input 'gr' in the line x
module Main where
import PGF
import System.Environment
import System.IO
main :: IO ()
main = do
file:_ <- getArgs
gr <- readPGF file
content <- readFile "input.txt"
writeFile "output.txt" &(translate gr content)
translate :: PGF -> String -> String
translate gr s = case parseAllLang gr (startCat gr) s of
(lg,t:_):_ -> unlines [linearize gr l t | l <- languages gr, l /= lg]
_ -> "NO PARSE"
In this code I want to read a line(string) from input file and bind it to content. after that pass the content and PGF file(gr) to translate function and finally write the processed string via translate function on output file.
What is wrong with this code, and how can I fix it?
Don't indent the definition of
translate
. It should line up directly below its type signature.Do indent the body of
main
. The line afterdo
needs to be indented, otherwise the layout rule will dictate that everything following it is part of thedo
block.I think you're borrowing
&
from another language. You should write that line as eitheror
(Which are identical; the operator
$
is used in Haskell to eliminate the need for parentheses.)