load "TextIO"; load "String"; load "Int"; load "Option"; (* fileToList "infile" åbner infile og outputter dette som en liste af typen '(int * string * string) list' *) fun fileToList infile = let val inf = TextIO.openIn infile val st = String.tokens (fn x => x = #",") (TextIO.inputLine(inf)) val navn = hd (st) val pris = Option.valOf (Int.fromString (hd (tl (st)))) val vare = String.substring(hd (tl( tl( st))),0, size(hd (tl( tl( st))))-1) val koeb = (pris, navn, vare) in if TextIO.endOfStream inf then koeb :: [] else koeb :: (fileToList infile) end; (* giver fejlen: ! Uncaught exception: ! Io {cause = SysErr ("Too many open files", SOME), function = "openIn", name = "thisisatest.txt"} *)