Domanda

I want to write a very simple OCaml program which will take a single line of ints separated by spaces e.g.

1 2 5 8 12 363 9

and store this as a list of ints i.e. [1;2;5;8;12;363;9]. How do I do this in a clean way?

È stato utile?

Soluzione

#require "str";;

let list_of_line line = Str.split (Str.regexp_string " ") line |> List.map int_of_string
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top