How to get a string from TextIO in sml/ml?

大兔子大兔子 提交于 2019-12-11 04:37:19

问题


I'm trying to read text from a file in SML. Eventually, I want a list of individual words; however, I'm struggling at how to convert between a TextIO.elem to a string. For example, if I write the following code it returns a TextIO.elem but I don't know how to convert it to a string so that I can concat it with another string

TextIO.input1 inStream


回答1:


TextIO.elem is just a synonym for char, so you can use the str function to convert it to a string. But as I replied to elsewhere, I suggest using TextIO.inputAll to get a string right away.

Here is a function that takes an instream and delivers all (remaining) words in it:

val words = String.tokens Char.isSpace o TextIO.inputAll

The type of this function is TextIO.instream -> string list.



来源:https://stackoverflow.com/questions/14529807/how-to-get-a-string-from-textio-in-sml-ml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!