How to fix "parse error on input" error in haskell?
Prelude Data.Set> :load hello
[1 of 1] Compiling Main ( hello.hs, interpreted )
hello.hs:11:11: parse error on input `<-'
Failed, modules loaded: none.
Prelude Data.Set> h <- IO.openFile "testtext" IO.ReadMode
Prelude Data.Set>
On the same line [h <- IO.openFile "testtext" IO.ReadMode] inside hello.hs throws an error. How to fix it? What am I doing wrong?
[EDIT] Source and output: http://pastebin.com/KvEvggQK
You can use <-inside do-block (which you implicitly in GHCI, but not in Haskell files).
In a Haskell file, you are only allowed to write bindings with =.
What you can do is put the following in a Haskell file:
myHandle = do h <- IO.openFile "testtext" IO.ReadMode
return h
Although, if you think about it a little, it will be exactly the same as:
myHandle = IO.openFile "testtext" IO.ReadMode
myHandle - IO, <- ( >>=) ghci, .
Haskell , , testtext .
¹ , <- , .