open TextIO; exception Eof; fun digit(c) = c >= #"0" andalso c <= #"9"; fun startInt(file) = startInt1(file, input1(file)) and startInt1(file, NONE) = raise Eof | startInt1(file, SOME c) = if digit(c) then ord(c)-ord(#"0") else startInt(file); fun finishInt(i,file) = finishInt1(i,file,input1(file)) and finishInt1(i, file, NONE) = i | finishInt1(i, file, SOME c) = if digit(c) then finishInt(10*i+ord(c)-ord(#"0"), file) else i; fun getInt(file) = finishInt(startInt(file), file) fun sumInts1(file) = (getInt(file) + sumInts1(file)) handle Eof => 0; fun sumInts(filename) = sumInts1(openIn(filename));