# HG changeset patch # User Edward Z. Yang # Date 1343335717 14400 # Node ID f55f66c6fdeef109db6f195360ae7d182d6756f3 # Parent ca1c07d49b5e6746036edcc6ff9c62b7d335abd9 Migrate ap method to Record module. diff -r ca1c07d49b5e -r f55f66c6fdee lib.urp --- 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 diff -r ca1c07d49b5e -r f55f66c6fdee record.ur --- 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 diff -r ca1c07d49b5e -r f55f66c6fdee record.urs --- 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) diff -r ca1c07d49b5e -r f55f66c6fdee variant.ur --- 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))