annotate record.ur @ 28:f55f66c6fdee
Migrate ap method to Record module.
author |
Edward Z. Yang <ezyang@mit.edu> |
date |
Thu, 26 Jul 2012 16:48:37 -0400 |
parents |
6cd839818393 |
children |
|
rev |
line source |
adam@11
|
1 fun numFields [r ::: {Type}] (fl : folder r) (r : $r) : int =
|
adam@11
|
2 @fold [fn _ => int] (fn [nm ::_] [u ::_] [r ::_] [[nm] ~ r] acc => acc+1) 0 fl
|
adam@11
|
3
|
adam@10
|
4 fun mem [a ::: Type] [ns ::: {Unit}] (_ : eq a) (fl : folder ns) (x : a) (r : $(mapU a ns)) : bool =
|
adam@10
|
5 @foldUR [a] [fn _ => bool]
|
adam@10
|
6 (fn [nm ::_] [r ::_] [[nm] ~ r] y acc =>
|
adam@10
|
7 acc || x = y)
|
adam@10
|
8 False fl r
|
adam@12
|
9
|
adam@12
|
10 fun equal [ts ::: {Type}] (eqs : $(map eq ts)) (fl : folder ts) (r1 : $ts) (r2 : $ts) : bool =
|
adam@18
|
11 @foldR3 [eq] [ident] [ident] [fn _ => bool]
|
adam@12
|
12 (fn [nm ::_] [t ::_] [r ::_] [[nm] ~ r] isEq x y acc =>
|
adam@12
|
13 acc && @eq isEq x y)
|
adam@12
|
14 True fl eqs r1 r2
|
ezyang@28
|
15
|
ezyang@28
|
16 fun ap [K] [tf1 :: K -> Type] [tf2 :: K -> Type]
|
ezyang@28
|
17 [r ::: {K}] (fl : folder r) (fs : $(map (fn t => tf1 t -> tf2 t) r)) (xs : $(map tf1 r))
|
ezyang@28
|
18 = @map2 [fn t => tf1 t -> tf2 t] [fn t => tf1 t] [tf2] (fn [t] f x => f x) fl fs xs
|