开发者

convert string to list in Standard ML [duplicate]

开发者 https://www.devze.com 2022-12-19 10:57 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Open file in ML(SMLNJ) I have a string value which has value like this:
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Open file in ML(SMLNJ)

I have a string value which has value like this:

"[(1,2,3),(2,3),(6,8)]" -> string

but I want to have these values in int type like this:

[(1,2,3),(2,3),(6,8)] ->   (int list) list

what should I do?is there any function which can help me? or I have to do 开发者_开发百科it myself?


This problem is perfectly suited to parsing combinators, which you can steal from my friend Greg Morrisett at Harvard.

If you want to understand the underlying ideas, read Graham Hutton's paper Higher-Order Functions for Parsing. If you want to know how to implement I/O in Standard ML, consult the TextIO module in the Standard Basis Library. If you want someone to write the code for you, you may have reached the wrong web site.


You can use stringint from the String module. See for example http://wwwcgi.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/ml/help/string#Character%20Transformation%20Functions

0

精彩评论

暂无评论...
验证码 换一张
取 消