Skip to content

Instantly share code, notes, and snippets.

@thoughtpolice
Created June 15, 2011 19:47
Show Gist options
  • Save thoughtpolice/1027935 to your computer and use it in GitHub Desktop.
Save thoughtpolice/1027935 to your computer and use it in GitHub Desktop.
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 -> xtable]
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc mr x =>
<xml><tr><th>{[ mr.nm.Label ]}</th><td>
{[ mr.nm.Show x.nm ]}</td></tr>
{ acc (mr -- nm) (x -- nm) }
</xml>)
(fn _ _ => <xml></xml>) fl mr x
fun main () =
let
val f = mkTable { A = { Label = "A", Show = @show show_int }
, B = { Label = "B", Show = @show show_float }
}
in
return <xml><body>
<table border=1>{f { A = 1, B = 1.2 }}</table>
</body></xml>
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment