该函数将实数的列表保存到文件:SML:如何写在文件两个清单ML
fun writeReal (real, filename) =
let val fd = TextIO.openOut filename
val _ = map (fn i => TextIO.output (fd, Real.toString i^"\r\n")) real
val _ = TextIO.closeOut fd
in() end
调用函数:
writeReal ([1.0,2.0,3.0,4.0], "hello.txt")
将以下内容写入文件hello.txt的:
1.0
2.0
3.0
4.0
如果我有两个表,一个包含实数的列表,另一个是单词列表,我如何读取和写入这两个列表到文件中?例如:
writeReal ([1.0,2.0,3.0,4.0], [one, two, three, four] , "hello.txt")
应该写下面的文件hello.txt的:
1.0 one
2.0 two
3.0 three
4.0 four