[Ur] Save recursive datatype in a DB

Marco Maggesi maggesi at math.unifi.it
Mon Apr 14 03:13:50 EDT 2014


Hi,

I'm new to Ur/Web and I'm very impressed by the whole conception of the
language and the framework.  I would like to develop a small test program
to better get the feeling of the system.

I have a tree-like datatype as follows

datatype tree =
  | Leaf of { Label : string }
  | Node of { Label : string, Children : list tree}

and I would like to write values of tree type inside an SQL database.

Of course I can encode the tree structure in a corresponding
Parent-Children table (as it is done in the "Tree" demo from the web site),
but this is not what I would like to do, since i tend to consider these
tree object as "atomic" values that are saved retrieved and queried all at
once.

Of course it is easy to write a serialisation function
  encodeString : tree -> string
or
  encodeXml : tree -> xbody
which already did and this allows in a simple way to save trees in the db.

The problem is reading back the values from the database (i.e., from the
string or the xml encoding), i.e. write functions
  decodeString : string -> option tree
Does Ur has tools that can easy this task?
If I understand correctly, xml support is builtin in the sml implementation
and no primitive for reading xml and/or analysing (pattern matching etc)
are developed so far.

Are there other option than manually write a parser?

Thanks,
Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20140414/c225a6e5/attachment.html>


More information about the Ur mailing list