My function is trying to read a textfile line by line and carry out a certain predefined function on each line called somefn and append the value of somefn to the function. The somefn is already defined above this and works fine.
fun extractline(infile:string)=
let
val insl=TextIO.inputLine(ins)
case insl of
NONE=> []
|SOME(l)=>somefn(insl)::extractline(infile)
in
TextIO.closeIn(ins);
end
;
I am having errors and cannot handle them.
I would appreciate some help.
Thank You.
Remember, in
let ... in ... endblocks, you place declarations you need betweenletandi n, and the resulting expression betweeninandend.As such, you need your
caseexpression placed betweeninandend.You also never open the stream,
ins. Make your function open the stream, and then work recursively on that stream in another function, however; you don’t want to open the file for each recursive call.You’ll want something on this form:
Then you make
extractline_hbe recursive, and build up the list in that.