annotate mem.ur @ 30:4e673b535434

Optimizing JSON generation
author Adam Chlipala <adam@chlipala.net>
date Thu, 04 Dec 2014 19:52:51 -0500
parents 744bf911dcc6
children
rev   line source
adam@5 1 con mem' = K ==> fn (nm :: Name) (t :: K) (r :: {K}) (r' :: {K}) =>
adam@5 2 [[nm] ~ r'] => {Expose : f :: ({K} -> Type) -> f r -> f ([nm = t] ++ r'),
adam@5 3 Hide : f :: ({K} -> Type) -> f ([nm = t] ++ r') -> f r}
adam@5 4
adam@5 5 con mem = K ==> fn (nm :: Name) (t :: K) (r :: {K}) =>
adam@5 6 tp :: Type -> (r' :: {K} -> [[nm] ~ r'] => mem' nm t r r' -> tp) -> tp
adam@5 7
adam@5 8 fun mem [K] [nm :: Name] [t :: K] [r :: {K}] [[nm] ~ r] =
adam@5 9 fn [tp :: Type] (f : r' :: {K} -> [[nm] ~ r'] => mem' nm t ([nm = t] ++ r) r' -> tp) =>
adam@14 10 f [r] (fn [[nm] ~ r] => {Expose = fn [f :: {K} -> Type] x => x,
adam@14 11 Hide = fn [f :: {K} -> Type] x => x})
adam@5 12
adam@5 13 fun mp [K] [K2] [f :: K -> K2] [nm ::: Name] [t ::: K] [r ::: {K}] (m : mem nm t r) =
adam@5 14 m [mem nm (f t) (map f r)] (fn [r' :: {K}] [[nm] ~ r'] (m' : mem' nm t r r') =>
adam@5 15 fn [tp :: Type] (f : r' :: {K2} -> [[nm] ~ r'] =>
adam@5 16 mem' nm (f t) (map f r) r' -> tp) =>
adam@14 17 f [map f r'] (fn [[nm] ~ map f r'] =>
adam@14 18 {Expose = fn [f' :: {K2} -> Type] x =>
adam@14 19 m'.Expose [fn r => f' (map f r)] x,
adam@14 20 Hide = fn [f' :: {K2} -> Type] x =>
adam@14 21 m'.Hide [fn r => f' (map f r)] x}))
adam@5 22
adam@5 23 fun proj [nm ::: Name] [t ::: Type] [r ::: {Type}] (m : mem nm t r) (r : $r) =
adam@5 24 m [t] (fn [r' :: {Type}] [[nm] ~ r'] (m' : mem' nm t r r') =>
adam@5 25 (m'.Expose [fn r => $r] r).nm)
adam@5 26
adam@5 27 fun replace [nm ::: Name] [t ::: Type] [r ::: {Type}] (m : mem nm t r) (r : $r) (v : t) =
adam@5 28 m [$r] (fn [r' :: {Type}] [[nm] ~ r'] (m' : mem' nm t r r') =>
adam@5 29 m'.Hide [fn r => $r] (m'.Expose [fn r => $r] r -- nm ++ {nm = v}))
adam@5 30
adam@5 31 fun fold [K] [tf :: ({K} -> Type)] [r ::: {K}]
adam@5 32 (f : nm :: Name -> v :: K -> r' :: {K} -> [[nm] ~ r']
adam@5 33 => mem nm v r -> tf r' -> tf ([nm = v] ++ r'))
adam@5 34 (i : tf []) (fl : folder r) =
adam@5 35 @@Incl.fold [tf] [r]
adam@5 36 (fn [nm :: Name] [v :: K] [r' :: {K}] [[nm] ~ r'] (i : Incl.incl ([nm = v] ++ r') r) acc =>
adam@14 37 f [nm] [v] [r'] (Incl.inv1 [nm] [v] [r'] [r] [mem] i mem) acc)
adam@5 38 i fl