'SML Convert integer to list
The below code is able to successfully convert an integer file to a list however i need to convert an integer to a list such as. Can anyone assist please ?
readint 134516; result should be a list [1,3,4,5,1,6];
fun readint(infile : string) =
let
val ins = TextIO.openIn infile
fun loop ins =
case TextIO.scanStream (Int.scan StringCvt.DEC) ins of
SOME int => int :: loop ins
| NONE => []
in
loop ins before TextIO.closeIn ins
end;
Solution 1:[1]
You want to to create a recursive function that uses the modulo (mod) and integer division (div) operators.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fredrik Arnerup |
