Using Top.Fold to count fields of a record
From Impredicative Wiki
Revision as of 11:04, 8 December 2010 by Karn Kallio (Talk | contribs)
This code example shows a use of Top.Fold to count the fields of a type level record.
con rr :: {Type} = [One = int, Two = string, Three = bool, Four = list float]
val q : int = @@fold [fn (rx :: {Type}) => (int)]
(fn [nm :: Name] [t :: Type] [r :: {Type}] [[nm] ~ r] acc => 1 + acc) (0) [rr] (_ : folder rr)
fun main () = return <xml>
<head> <title>Count fields of a record type</title> </head> <body>
Count fields of a record type
We can use fold to count the fields in a type level record.
Here is the value of q: {[q]}
</body>
</xml>