Mercurial > meta
changeset 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 | ca1c07d49b5e |
children | 7530b2b54353 |
files | lib.urp record.ur record.urs variant.ur |
diffstat | 4 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib.urp Thu Jul 26 16:39:02 2012 -0400 +++ b/lib.urp Thu Jul 26 16:48:37 2012 -0400 @@ -4,9 +4,9 @@ incl mem eq +record variant json -record sql parse html
--- a/record.ur Thu Jul 26 16:39:02 2012 -0400 +++ b/record.ur Thu Jul 26 16:48:37 2012 -0400 @@ -12,3 +12,7 @@ (fn [nm ::_] [t ::_] [r ::_] [[nm] ~ r] isEq x y acc => acc && @eq isEq x y) True fl eqs r1 r2 + +fun ap [K] [tf1 :: K -> Type] [tf2 :: K -> Type] + [r ::: {K}] (fl : folder r) (fs : $(map (fn t => tf1 t -> tf2 t) r)) (xs : $(map tf1 r)) + = @map2 [fn t => tf1 t -> tf2 t] [fn t => tf1 t] [tf2] (fn [t] f x => f x) fl fs xs
--- a/record.urs Thu Jul 26 16:39:02 2012 -0400 +++ b/record.urs Thu Jul 26 16:48:37 2012 -0400 @@ -5,3 +5,10 @@ val equal : ts ::: {Type} -> $(map eq ts) -> folder ts -> $ts -> $ts -> bool (* Are two records equal? *) + +(* Analogous to applicative ap e.g. <*>, of type [f (a -> b) -> f a -> f b] *) +val ap : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) + -> r ::: {K} -> folder r + -> $(map (fn t => tf1 t -> tf2 t) r) + -> $(map tf1 r) + -> $(map tf2 r)
--- a/variant.ur Thu Jul 26 16:39:02 2012 -0400 +++ b/variant.ur Thu Jul 26 16:48:37 2012 -0400 @@ -142,4 +142,4 @@ fun declareCase [ts] [t] [a] (f : (a -> variant ts) -> a -> t) : type_case ts t a = f fun typeCase [ts] [t] (v : variant ts) (dstrs : $(map (type_case ts t) ts)) (fl : folder ts) : t (* Ur/Web not clever enough to calculate these folders, it seems *) - = match v (@ap [fn a => a -> variant ts] [fn a => a -> t] fl dstrs (@mkLabels fl)) + = match v (@Record.ap [fn a => a -> variant ts] [fn a => a -> t] fl dstrs (@mkLabels fl))