Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocaml - string to (int*int*int) list

Is in ocaml function which can parse string like this "[(1,2,3);(1,2,5);(2,3,4)]" into (int*int*int) list ? or do I have to write my own parsing function ?

Thanks

Greg

like image 814
Greg Avatar asked Jun 17 '11 16:06

Greg


1 Answers

Well, it should not be too difficult with help of the Scanf module from the standard library -- you will be able to scan the triples easily and then only have to add a bit of logic to parse a list.

Alternatively you can take a look at deriving:

Extension to OCaml for deriving functions from type declarations. Includes derivers for pretty-printing, type-safe marshalling with structure-sharing, dynamic typing, equality, and more.

like image 150
akoprowski Avatar answered Oct 20 '22 19:10

akoprowski