val file = TextIO.openIn "day_1.txt"; val input = TextIO.inputAll file; TextIO.closeIn file; val result = let val lines = String.tokens (fn (char) => char = #"\n") input in let val numbers = map (fn (line) => let val digits = List.filter Char.isDigit (String.explode line) in Int.fromString (String.implode [List.hd digits, List.last digits]) end) lines in let val numbers = map Option.valOf (List.filter Option.isSome numbers) in List.foldl (fn (v, acc) => v + acc) 0 numbers end end end;