I am new to SML of NJ and I am trying to do a problem in it. I need help in unde
ID: 3795584 • Letter: I
Question
I am new to SML of NJ and I am trying to do a problem in it. I need help in understanding how to read a text file line by line in SML. So lets say my text file was named inFile. Heres what the inFile would look like.
My dog jumped for the frisbee
I play outside a lot
I jumped into the pool yesterday
I need to have it read this file so I can call a function on each particular line as a string in SML. How would you go about doing this.
Explanation / Answer
val infile = "c:/input.txt" ; fun readlist (infile : string) = let val ins = TextIO.openIn infile fun loop ins = case TextIO.inputLine ins of SOME line => line :: loop ins | NONE => [] in loop ins before TextIO.closeIn ins end ;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.