annotate incl.ur @ 6:799f43bce62b

Import some code from iwl
author Adam Chlipala <adam@chlipala.net>
date Tue, 14 Dec 2010 10:33:24 -0500
parents 943410267fad
children 744bf911dcc6
rev   line source
adam@5 1 con incl' = K ==> fn (r1 :: {K}) (r2 :: {K}) (r' :: {K}) =>
adam@5 2 [r1 ~ r'] => {Expose : f :: ({K} -> Type) -> f r2 -> f (r1 ++ r'),
adam@5 3 Hide : f :: ({K} -> Type) -> f (r1 ++ r') -> f r2}
adam@5 4
adam@5 5 con incl = K ==> fn (r1 :: {K}) (r2 :: {K}) =>
adam@5 6 tp :: Type -> (r' :: {K} -> [r1 ~ r'] => incl' r1 r2 r' -> tp) -> tp
adam@5 7
adam@5 8 fun incl [K] [r1 :: {K}] [r2 :: {K}] [r1 ~ r2] =
adam@5 9 fn [tp :: Type] (f : r' :: {K} -> [r1 ~ r'] => incl' r1 (r1 ++ r2) r' -> tp) =>
adam@5 10 f [r2] ! (fn [r1 ~ r2] => {Expose = fn [f :: ({K} -> Type)] x => x,
adam@5 11 Hide = fn [f :: ({K} -> Type)] x => x})
adam@5 12
adam@5 13 fun proj [r1 ::: {Type}] [r2 ::: {Type}] (i : incl r1 r2) (r : $r2) =
adam@5 14 i [$r1] (fn [r' :: {Type}] [r1 ~ r'] (i' : incl' r1 r2 r') =>
adam@5 15 i'.Expose [fn r => $r] r --- r')
adam@5 16
adam@5 17 fun inv1 [K] [nm :: Name] [t :: K] [r :: {K}] [r' :: {K}] [[nm] ~ r]
adam@5 18 [f :: Name -> K -> {K} -> Type]
adam@5 19 (i : incl ([nm = t] ++ r) r')
adam@5 20 (f : nm :: Name -> t :: K -> r :: {K} -> [[nm] ~ r] => f nm t ([nm = t] ++ r)) =
adam@5 21 i [f nm t r'] (fn [r'' :: {K}] [[nm = t] ++ r ~ r''] (i' : incl' ([nm = t] ++ r) r' r'') =>
adam@5 22 i'.Hide [f nm t] (f [nm] [t] [r ++ r''] !))
adam@5 23
adam@5 24 fun inv2 [K] [nm :: Name] [t :: K] [r :: {K}] [r' :: {K}] [[nm] ~ r]
adam@5 25 (i : incl ([nm = t] ++ r) r') =
adam@5 26 i [incl r r'] (fn [r'' :: {K}] [[nm = t] ++ r ~ r''] (i' : incl' ([nm = t] ++ r) r' r'') =>
adam@5 27 fn [tp :: Type] (f : r''' :: {K} -> [r ~ r'''] => incl' r r' r''' -> tp) =>
adam@5 28 f [[nm = t] ++ r''] ! (fn [r ~ [nm = t] ++ r''] =>
adam@5 29 {Expose = fn [f :: ({K} -> Type)] (x : f r') => i'.Expose [f] x,
adam@5 30 Hide = fn [f :: ({K} -> Type)] x => i'.Hide [f] x}))
adam@5 31
adam@5 32 fun fold [K] [tf :: {K} -> Type] [r ::: {K}]
adam@5 33 (f : nm :: Name -> v :: K -> r' :: {K}
adam@5 34 -> [[nm] ~ r'] => incl ([nm = v] ++ r') r -> tf r' -> tf ([nm = v] ++ r'))
adam@5 35 (i : tf []) (fl : folder r) =
adam@5 36 @Top.fold [fn r' => incl r' r -> tf r']
adam@5 37 (fn [nm :: Name] [v :: K] [r' :: {K}] [[nm] ~ r'] acc i =>
adam@5 38 f [nm] [v] [r'] ! i (acc (inv2 [nm] [v] [r'] [r] i)))
adam@5 39 (fn _ => i)
adam@5 40 fl (incl [r] [[]])