annotate demo/treeFun.ur @ 805:e2780d2f4afc

Mutual datatypes through Elaborate
author Adam Chlipala <adamc@hcoop.net>
date Sat, 16 May 2009 15:14:17 -0400
parents 311ca1ae715d
children
rev   line source
adamc@469 1 functor Make(M : sig
adamc@469 2 type key
adamc@469 3 con id :: Name
adamc@469 4 con parent :: Name
adamc@469 5 con cols :: {Type}
adamc@469 6 constraint [id] ~ [parent]
adamc@469 7 constraint [id, parent] ~ cols
adamc@469 8
adamc@723 9 val key_inj : sql_injectable_prim key
adamc@469 10
adamc@706 11 table tab : ([id = key, parent = option key] ++ cols)
adamc@469 12 end) = struct
adamc@469 13
adamc@469 14 open M
adamc@469 15
adamc@469 16 fun tree (f : $([id = key, parent = option key] ++ cols) -> xbody)
adamc@469 17 (root : option M.key) =
adamc@469 18 let
adamc@469 19 fun recurse (root : option key) =
adamc@471 20 queryX' (SELECT * FROM tab WHERE {eqNullable' (SQL tab.{parent}) root})
adamc@469 21 (fn r =>
adamc@469 22 children <- recurse (Some r.Tab.id);
adamc@469 23 return <xml>
adamc@469 24 <li> {f r.Tab}</li>
adamc@469 25
adamc@469 26 <ul>
adamc@469 27 {children}
adamc@469 28 </ul>
adamc@469 29 </xml>)
adamc@469 30 in
adamc@469 31 recurse root
adamc@469 32 end
adamc@469 33
adamc@469 34 end