Created
June 14, 2011 22:43
-
-
Save thoughtpolice/1026117 to your computer and use it in GitHub Desktop.
urweb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
con meta t = { Label : string | |
, Show : t -> string } | |
fun mkTable [r ::: {Type}] (fl : folder r) (mr : $(map meta r)) (x : $r) = | |
@fold [fn r => $(map meta r) -> $r -> string] | |
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc mr x => | |
"<tr> <th>" ^ mr.nm.Label ^ "</th> <td>" | |
^ mr.nm.Show x.nm ^ "</td></tr>" | |
^ (acc (mr -- nm) (x -- nm))) | |
(fn _ _ => "") fl mr x | |
fun mkTable2 [r ::: {Type}] (fl : folder r) (mr : $(map meta r)) (x : $r) = | |
@fold [fn r => $(map meta r) -> $r -> xtable] | |
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc mr x => | |
<tr><th>{[mr.nm.Label]}</th></tr> | |
<tr> | |
:: td (mr.nm.Show x.nm) | |
:: [])) | |
(acc (mr -- nm) (x -- nm))) | |
(fn _ _ => empty) fl mr x | |
fun main () = | |
let | |
val f = mkTable2 { A = { Label = "A", Show = @show show_int } | |
, B = { Label = "B", Show = @show show_float } | |
} | |
in | |
return <xml><body> | |
{[ tabl (f { A = 1, B = 1.2 })]} | |
</body></xml> | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment