comparison mem.ur @ 5:943410267fad

Import Incl and Mem
author Adam Chlipala <adam@chlipala.net>
date Tue, 14 Dec 2010 09:49:10 -0500
parents
children 744bf911dcc6
comparison
equal deleted inserted replaced
4:8f7396495045 5:943410267fad
1 con mem' = K ==> fn (nm :: Name) (t :: K) (r :: {K}) (r' :: {K}) =>
2 [[nm] ~ r'] => {Expose : f :: ({K} -> Type) -> f r -> f ([nm = t] ++ r'),
3 Hide : f :: ({K} -> Type) -> f ([nm = t] ++ r') -> f r}
4
5 con mem = K ==> fn (nm :: Name) (t :: K) (r :: {K}) =>
6 tp :: Type -> (r' :: {K} -> [[nm] ~ r'] => mem' nm t r r' -> tp) -> tp
7
8 fun mem [K] [nm :: Name] [t :: K] [r :: {K}] [[nm] ~ r] =
9 fn [tp :: Type] (f : r' :: {K} -> [[nm] ~ r'] => mem' nm t ([nm = t] ++ r) r' -> tp) =>
10 f [r] ! (fn [[nm] ~ r] => {Expose = fn [f :: {K} -> Type] x => x,
11 Hide = fn [f :: {K} -> Type] x => x})
12
13 fun mp [K] [K2] [f :: K -> K2] [nm ::: Name] [t ::: K] [r ::: {K}] (m : mem nm t r) =
14 m [mem nm (f t) (map f r)] (fn [r' :: {K}] [[nm] ~ r'] (m' : mem' nm t r r') =>
15 fn [tp :: Type] (f : r' :: {K2} -> [[nm] ~ r'] =>
16 mem' nm (f t) (map f r) r' -> tp) =>
17 f [map f r'] ! (fn [[nm] ~ map f r'] =>
18 {Expose = fn [f' :: {K2} -> Type] x =>
19 m'.Expose [fn r => f' (map f r)] x,
20 Hide = fn [f' :: {K2} -> Type] x =>
21 m'.Hide [fn r => f' (map f r)] x}))
22
23 fun proj [nm ::: Name] [t ::: Type] [r ::: {Type}] (m : mem nm t r) (r : $r) =
24 m [t] (fn [r' :: {Type}] [[nm] ~ r'] (m' : mem' nm t r r') =>
25 (m'.Expose [fn r => $r] r).nm)
26
27 fun replace [nm ::: Name] [t ::: Type] [r ::: {Type}] (m : mem nm t r) (r : $r) (v : t) =
28 m [$r] (fn [r' :: {Type}] [[nm] ~ r'] (m' : mem' nm t r r') =>
29 m'.Hide [fn r => $r] (m'.Expose [fn r => $r] r -- nm ++ {nm = v}))
30
31 fun fold [K] [tf :: ({K} -> Type)] [r ::: {K}]
32 (f : nm :: Name -> v :: K -> r' :: {K} -> [[nm] ~ r']
33 => mem nm v r -> tf r' -> tf ([nm = v] ++ r'))
34 (i : tf []) (fl : folder r) =
35 @@Incl.fold [tf] [r]
36 (fn [nm :: Name] [v :: K] [r' :: {K}] [[nm] ~ r'] (i : Incl.incl ([nm = v] ++ r') r) acc =>
37 f [nm] [v] [r'] ! (Incl.inv1 [nm] [v] [r'] [r] [mem] i mem) acc)
38 i fl