
Hello, everyone. I need help for my first code. I write this code for extracting one sentence from text file. The code is ----------------------------------------------------------------------------------------------------------------------- import System import System.Random main = do myHeader <- readFile "C:\\Documents and Settings\\myHeader.txt" putStrLn $ myExtractSentence myHeader myExtractSentence file = ary !! ranNoInt where ranNoInt =<< ranNo -- *mark ranNo = randomRIO (0, n-1) n = length ary ary = lines file ---------------------------------------------------------------------------------------------------------------------- There are two questions. 1) I've got following error message. Haskell>ghc --make Test01.hs -o Test [1 of 1] Compiling Main ( Test01.hs, Test01.o ) Test01.hs:10:9: parse error (possibly incorrect indentation) How can fix it? 2) Is it OK at "*mark" line? Thank you. S. CHANG

On Tue, 26 Oct 2010 08:36:58 +0200, Sok H. Chang
import System import System.Random
main = do myHeader <- readFile "C:\\Documents and Settings\\myHeader.txt" putStrLn $ myExtractSentence myHeader myExtractSentence file = ary !! ranNoInt where ranNoInt =<< ranNo -- *mark ranNo = randomRIO (0, n-1) n = length ary ary = lines file ---------------------------------------------------------------------------------------------------------------------- There are two questions.
1) I've got following error message. Haskell>ghc --make Test01.hs -o Test [1 of 1] Compiling Main ( Test01.hs, Test01.o )
Test01.hs:10:9: parse error (possibly incorrect indentation)
How can fix it?
The lay-out is wrong: putStrLn should be in the same column as the "myHeader" above it; avoid tabs to prevent unexpected lay-out problems. The lay-out could be like this: ----------------------------------------------------------------------------------------------------------------------- main = do myHeader <- readFile "C:\\Documents and Settings\\myHeader.txt" putStrLn $ myExtractSentence myHeader -----------------------------------------------------------------------------------------------------------------------
2) Is it OK at "*mark" line?
Note that ranNoInt is a value inside the IO monad, you cannot use directly as an index. Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html --

2) No.
1) That is your syntax error. You should have "ranNoInt = <something>".
The =<< operator is meant for the definition of the function.
Try this:
import System
import System.Random
main = readFile "C:\\Documents and Settings\\myHeader.txt" >>=
myExtractSentence >>= putStrLn
myExtractSentence file = do
ranNoInt <- ranNo
return $ ary !! ranNoInt
where
ranNo = randomRIO (0, n-1)
n = length ary
ary = lines file
On Tue, Oct 26, 2010 at 2:36 AM, Sok H. Chang
Hello, everyone.
I need help for my first code. I write this code for extracting one sentence from text file.
The code is
----------------------------------------------------------------------------------------------------------------------- import System import System.Random
main = do myHeader <- readFile "C:\\Documents and Settings\\myHeader.txt" putStrLn $ myExtractSentence myHeader myExtractSentence file = ary !! ranNoInt where ranNoInt =<< ranNo -- *mark ranNo = randomRIO (0, n-1) n = length ary ary = lines file
---------------------------------------------------------------------------------------------------------------------- There are two questions.
1) I've got following error message. Haskell>ghc --make Test01.hs -o Test [1 of 1] Compiling Main ( Test01.hs, Test01.o )
Test01.hs:10:9: parse error (possibly incorrect indentation)
How can fix it?
2) Is it OK at "*mark" line?
Thank you.
S. CHANG
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Just a meta-observation: although such a program might be easy in other languages, a program involving file I/O and random number generation is probably not a very good choice for one's first Haskell program! Is there a particular book or tutorial you are following along with? -Brent On Tue, Oct 26, 2010 at 03:36:58PM +0900, Sok H. Chang wrote:
Hello, everyone.
I need help for my first code. I write this code for extracting one sentence from text file.
The code is ----------------------------------------------------------------------------------------------------------------------- import System import System.Random
main = do myHeader <- readFile "C:\\Documents and Settings\\myHeader.txt" putStrLn $ myExtractSentence myHeader myExtractSentence file = ary !! ranNoInt where ranNoInt =<< ranNo -- *mark ranNo = randomRIO (0, n-1) n = length ary ary = lines file ---------------------------------------------------------------------------------------------------------------------- There are two questions.
1) I've got following error message. Haskell>ghc --make Test01.hs -o Test [1 of 1] Compiling Main ( Test01.hs, Test01.o )
Test01.hs:10:9: parse error (possibly incorrect indentation)
How can fix it?
2) Is it OK at "*mark" line?
Thank you.
S. CHANG
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Brent Yorgey
-
David McBride
-
Henk-Jan van Tuyl
-
Sok H. Chang