
Hello, everyone. Thank you so much to previous great answer! Now, I don't know how can I fix this. The error is, Haskell>ghc --make Temp.hs -o Temp.exe [1 of 1] Compiling Main ( Temp.hs, Temp.o ) Temp.hs:19:27: Not in scope: `inpStr' The code is, import System.IO import System.Random sentenceAry = [] main :: IO () main = do inh <- openFile "c:\\Documents and Settings\\shaegis\\inputFile.txt" ReadMode outh <- openFile "c:\\Documents and Settings\\shaegis\\outputFile.txt" WriteMode mainloop inh outh hClose inh hClose outh mainloop :: Handle -> Handle -> IO () mainloop inh outh = do ineof <- hIsEOF inh if ineof then do hPutStrLn outh inpStr return () else do inpStr <- hGetLine inh let sentenceAry = inpStr : [] mainloop inh outh I'm try to change like below, but I failed. mainloop :: Handle -> Handle -> IO () mainloop inh outh = do ineof <- hIsEOF inh if not ineof then do inpStr <- hGetLine inh let sentenceAry = inpStr : [] mainloop inh outh else do hPutStrLn outh inpStr return () I wonder why... Thank you. Sincerely, Sok Chang

Hello, everyone. Hello, I don't understand very well what you're trying to do in your code, but if it is simply reading from a file and put the output into another file
On 12/14/2010 07:24 AM, Sok H. Chang wrote: there is a better way: import System.IO import System.Random sentenceAry = [] main :: IO () main = do inh <- openFile "c:\\Documents and Settings\\shaegis\\inputFile.txt" ReadMode outh <- openFile "c:\\Documents and Settings\\shaegis\\outputFile.txt" WriteMode mainloop inh outh hClose inh hClose outh mainloop :: Handle -> Handle -> IO () mainloop inh outh = do ineof <- hIsEOF inh if ineof then return () else do inpStr <- hGetLine inh hPutStrLn outh inpStr mainloop inh outh I hope I've understood the problem.. In your code 'inpStr' wasn't in scope, because you've declared it only into else block.. Luca

Thank you so much, Luca.
Mmm... I want to make a "List of Sentence" from some text file.
inputFile.txt is like this.
--------------------------------
This is a pen.
Is this a pen?
etc...many sentence. Each line, only one sentence.
How can I make a list of sentence?
How can I declared inpStr?
Thank you.
Sincerely, Sok Chang
2010/12/14 Luca Toscano
On 12/14/2010 07:24 AM, Sok H. Chang wrote:
Hello, everyone.
Hello, I don't understand very well what you're trying to do in your code, but if it is simply reading from a file and put the output into another file there is a better way:
import System.IO import System.Random
sentenceAry = []
main :: IO () main = do inh <- openFile "c:\\Documents and Settings\\shaegis\\inputFile.txt" ReadMode outh <- openFile "c:\\Documents and Settings\\shaegis\\outputFile.txt" WriteMode mainloop inh outh hClose inh hClose outh
mainloop :: Handle -> Handle -> IO () mainloop inh outh = do ineof <- hIsEOF inh if ineof then return () else do inpStr <- hGetLine inh hPutStrLn outh inpStr mainloop inh outh
I hope I've understood the problem.. In your code 'inpStr' wasn't in scope, because you've declared it only into else block..
Luca
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Sok Ha, CHANG Open Mind Clinic/Academy, 1551-1, Sa-Dong, SangRok-Gu, AnSan-City, KyongGi-Do Tel: 031-407-6114 HP: openmind.ac / www.openmind.ac

On 12/14/2010 12:32 PM, Sok H. Chang wrote:
Thank you so much, Luca. Mmm... I want to make a "List of Sentence" from some text file.
inputFile.txt is like this. -------------------------------- This is a pen. Is this a pen? etc...many sentence. Each line, only one sentence.
How can I make a list of sentence? How can I declared inpStr?
Thank you.
Sincerely, Sok Chang
You're welcome! I am a beginner in haskell programming, it's interesting to work with others! By the way, this is the code: import System.IO import System.Random import Data.List main :: IO () main = do inh <- openFile "path_to_file" ReadMode prova <- (mainloop inh []) print prova hClose inh mainloop :: Handle -> [String] -> IO [String] mainloop inh list = do ineof <- hIsEOF inh if ineof then return list else do inpStr <- hGetLine inh mainloop inh (list ++ [inpStr]) This is my version, it works I think.. I hope this helps you!! Luca

On Dec 14, 2010, at 14:36, Luca Toscano wrote:
On 12/14/2010 12:32 PM, Sok H. Chang wrote:
Thank you so much, Luca. Mmm... I want to make a "List of Sentence" from some text file.
inputFile.txt is like this. -------------------------------- This is a pen. Is this a pen? etc...many sentence. Each line, only one sentence.
How can I make a list of sentence? How can I declared inpStr?
Thank you.
Sincerely, Sok Chang
You're welcome! I am a beginner in haskell programming, it's interesting to work with others! By the way, this is the code:
import System.IO import System.Random import Data.List
main :: IO () main = do inh <- openFile "path_to_file" ReadMode prova <- (mainloop inh []) print prova hClose inh
mainloop :: Handle -> [String] -> IO [String] mainloop inh list = do ineof <- hIsEOF inh if ineof then return list else do inpStr <- hGetLine inh mainloop inh (list ++ [inpStr])
the "list ++ [inpStr]" is not very efficient for files with lot's of sentences. (++) is implemented in a way that it goes through the whole "list" every time a new field is appended. So, it does a lot of work a multiple times. Instead you should consider to e.g. use "inpStr : list" and reverse the list in the end.
This is my version, it works I think.. I hope this helps you!!
Another solution would be main = do input <- readFile "path_to_file" let prova = lines input print prova Cheers, Bastian

Thank you so much ! Luca and Bastian !
Now, I can handle whole text file as one list.
I want to do this... extract one text, or eliminate one text(like "tail
LIST") etc...
Thank you.
Also very Thankful to Bastian.
I'll try readFile function.
Thank you again, and Have a nice day.
Sincerely, Sok Chang
2010/12/14 Luca Toscano
On 12/14/2010 12:32 PM, Sok H. Chang wrote:
Thank you so much, Luca. Mmm... I want to make a "List of Sentence" from some text file.
inputFile.txt is like this. -------------------------------- This is a pen. Is this a pen? etc...many sentence. Each line, only one sentence.
How can I make a list of sentence? How can I declared inpStr?
Thank you.
Sincerely, Sok Chang
You're welcome! I am a beginner in haskell programming, it's interesting to work with others! By the way, this is the code:
import System.IO import System.Random import Data.List
main :: IO () main = do inh <- openFile "path_to_file" ReadMode prova <- (mainloop inh []) print prova hClose inh
mainloop :: Handle -> [String] -> IO [String] mainloop inh list = do
ineof <- hIsEOF inh if ineof then return list
else do inpStr <- hGetLine inh mainloop inh (list ++ [inpStr])
This is my version, it works I think.. I hope this helps you!!
Luca
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Sok Ha, CHANG Open Mind Clinic/Academy, 1551-1, Sa-Dong, SangRok-Gu, AnSan-City, KyongGi-Do Tel: 031-407-6114 HP: openmind.ac / www.openmind.ac
participants (3)
-
Bastian Erdnüß
-
Luca Toscano
-
Sok H. Chang