[Haskell-beginners] Is this scope range problem?

Luca Toscano toscano.luca at gmail.com
Tue Dec 14 14:36:24 CET 2010


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






More information about the Beginners mailing list