From: Nicolas C. <war...@fr...> - 2004-07-24 10:32:46
|
> > Well, we've been talking before about adding a module in order to save > > config or data informations in a persistent storage (such as a file) but we > > couldn't agree on which was best. IMHO we need a hierarchical format with > > some structural semantics and a minimum of typing , all of that storable in > > an text only user editable format. XML would be enough even if not best > > before it's widely use and easy to interface with other programming language > > for data exchanges. I think CDB is not enough powerful - although > > convenient - so that we reach an agreement on it. > > I think it's been mentioned before, but just for completeness, YAML > (http://www.yaml.org/) is looking like a good choice in this area. Of > course, someone would need to step forward and write the parser, which > isn't going to be me at the moment ... > > Rich. As for me, the best format would be OCaml one. For example if you want to serialize a string option list , you will get : [None;Some "hello";None;Some "world";None;None;Some "\n"] This serialization that can print the correct name of constructors can be done by exploiting data found in CMI files. Same for deserialization , you could do something like : let t = make_type "string option list" in let x = (unserialize str t : string option list) in and this would be entirely safe. Another (full) sample : sample.ml ----------- type point = { x : int; y : int; } let p = { x : 3 ; y : -1 } in let cmi = Type.parse "sample.mli" in let t = Type.get cmi "point" in (* raise an exc if not found *) let str = Type.serialize p t in (* the string returned is "{ x : 3 ; y : -1 }" checking is done when serializing that runtime 'p' data can be correctly serialized using 't' type *) let p2 = (Type.unserialize str t : point) in (* return { x : 3 , y : -1 } runtime information , this is safe *only* if your CMI is up-to-date with currently compiled and running module *) ----------- More than that, we get here some kind of first-class types with interesting properties for reflexion and introspection. Quite difficult to write such a module, but so useful and easy to use when done. Regards, Nicolas Cannasse |