Skip to main content

Thread: Haskell question--handling EOF in interactive program


hello, i'm new haskell, , try use process files (i.e., tasks similar might done in awk). specifically, i'd process text input file until reaches eof printing output @ appropriate times, , maintain state it.

here's stab @ program kind of thing:
php code:
--simple interactive program with statetakes
--user input stringappends it to current state
--string, and prints the state string
--state string grows as program is run

main 
:: io ()
main helper("") --initial state is empty string

helper 
:: string -> io ()
helper initialstate = do
       
linein <- getline
       putstrln
(snd (transition (lineininitialstate)))
       
helper(fst (transition (lineininitialstate)))

--
pure function to implement logic--translates
--input and current state to next state and
--
output
transition 
:: (stringstring) -> (stringstring)
transition inpair = (nextstatenextstatewhere nextstate = (snd inpair) ++ (fst inpair
the problem @ end of input file, prints error message:

code:
interact.hs: <stdin>: hgetline: end of file
i figure eliminate message checking eof, i'm not sure how this. know of simple way this?

in advance

iseof

php code:
--simple interactive program with statetakes
--user input stringappends it to current state
--string, and prints the state string
--state string grows as program is run

import system
.io

main 
:: io ()
main helper("") --initial state is empty string

helper 
:: string -> io ()
helper initialstate = do end <- iseof
                         
if end
                             then putstr 
""
                             
else do linein <- getline
                                     putstrln
(snd (transition (lineininitialstate)))
                                     
helper(fst (transition (lineininitialstate)))

--
pure function to implement logic--translates
--input and current state to next state and
--
output
transition 
:: (stringstring) -> (stringstring)
transition inpair = (nextstatenextstatewhere nextstate = (snd inpair) ++ (fst inpair


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Haskell question--handling EOF in interactive program


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support