0

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?

Community
  • 1
  • 1
JGC
  • 12,737
  • 9
  • 35
  • 57

2 Answers2

3

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.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
  • This is probably not very helpful for him directly, but I agree with your answer. I was considering offering some advice; on rereading the explanation, I realized anything I said would fall on deaf ears, especially if I didn't provide the exact code. – nlucaroni Feb 03 '10 at 14:56
0

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

swegi
  • 4,046
  • 1
  • 26
  • 45
  • it is like to using explode function in String but first it will give me string again. second I don't know what are i & j and those depends on entry. – JGC Feb 02 '10 at 17:38
  • Well, you have to split the input string by yourself, but this should be easy with `explode` and `implode` – swegi Feb 02 '10 at 19:10