Search code examples
smlsmlnj

SMLNJ Parse list of strings into list of tuples with multiple datatypes


I have a list of strings that I would like to parse into a list of tuples.

more specifically:

val strlist = ["1, 2, 3, 'hello', 4, 5, false, 6, [1, 2, 3], [1, 2]",
               "6, 1, 3, 'world', 4, 5, true, 4, [1, 2], [4, 7, 5]",
               . . .] : string list

into

val tuplist = [(1, 2, 3, "hello", 4, 5, false, 6, [1, 2, 3], [1, 2]),
               (6, 1, 3, "world", 4, 5, true, 4, [1, 2], [4, 7, 5]),
               . . .] : (int * int * int * string * int * int * bool * int * int list * int list) list

Every list element has the same format.


Solution

  • Found it here: How can I parse String to (int * int) tuple in SML?

    Though i would just use String.fields to get out the strings, glue the list strings with ^, and convert the formats. I would just need an extra function to convert the list string into the sublist. Bit tedious, but not difficult.