Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 ;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote