open import Relation.Binary.PropositionalEquality using (_β‘_) open import Data.Product postulate βΈ : Set β Set K : Set π : Setβ π = Set β : Setβ β = Set record Preorder : Setβ where field X : π _β_ : X β X β β refl : β (x : X) β x β x trans : β {x y z : X} β x β y β y β z β x β z infixr 20 _β¨_ infixr 20 _β_ record _β¨_ (X : Preorder) (Y : Preorder) : Set where module X = Preorder X module Y = Preorder Y field f : X.X β Y.X mon : β {x y} β X._β_ x y β Y._β_ (f x) (f y) app : β {X Y} β (X β¨ Y) β Preorder.X X β Preorder.X Y app = _β¨_.f _$_ = app _β_ : Preorder β Preorder β Preorder X β Y = record { X = X β¨ Y ; _β_ = Ξ» f g β (x : X.X) β _β¨_.f f x βy _β¨_.f g x ; refl = Ξ» x xβ β _β¨_.mon x (X.refl xβ) ; trans = Ξ» p1 p2 x β Y.trans (p1 x) (p2 x) } where module X = Preorder X module Y = Preorder Y _βy_ = Y._β_ _β¨_β_ : (X : Preorder) β Preorder.X X β Preorder.X X β Set X β¨ x β x' = Preorder._β_ X x x' record _β¨_β£_ (X : Preorder) (x y : Preorder.X X) : Set where module X = Preorder X _β_ = X._β_ field to : x β y fro : y β x record _β_ (X : Preorder) (Y : Preorder) : Set where field to : X β¨ Y fro : Y β¨ X eqX : β x β X β¨ app fro (app to x) β£ x eqY : β y β Y β¨ app to (app fro y) β£ y record _β_ (X Y : Preorder) : Set where _βy_ = Preorder._β_ Y field emb : X β¨ Y prj : Y β¨ X projection : β y β Y β¨ app emb (app prj y) β y retraction : β x β X β¨ x β£ app prj (app emb x) op : Preorder β Preorder op X = record { X = X.X ; _β_ = Ξ» x y β y X.β x ; refl = X.refl ; trans = Ξ» p1 p2 β X.trans p2 p1 } where module X = Preorder X opF : β {X Y} β (X β¨ Y) β op X β¨ op Y opF {X}{Y} f = record { f = f.f ; mon = _β¨_.mon f } where module X = Preorder X module Y = Preorder Y module f = _β¨_ f product : Preorder β Preorder β Preorder product X Y = record { X = X.X Γ Y.X ; _β_ = Ξ» p1 p2 β (projβ p1 βx projβ p2) Γ (projβ p1 βy projβ p2) ; refl = Ξ» x β (X.refl (projβ x)) , (Y.refl (projβ x)) ; trans = Ξ» leq1 leq2 β (X.trans (projβ leq1) (projβ leq2)) , Y.trans (projβ leq1) (projβ leq2) } where module X = Preorder X _βx_ = X._β_ module Y = Preorder Y _βy_ = Y._β_ record FiberPts {X : Preorder}{Y : Preorder} (f : X β¨ Y) (y : Preorder.X Y) : Set where field pt : Preorder.X X over : _β¨_.f f pt β‘ y Fiber : {X : Preorder}{Y : Preorder} (f : X β¨ Y) (y : Preorder.X Y) β Preorder Fiber {X}{Y} f y = record { X = FiberPts f y ; _β_ = Ξ» x x' β FiberPts.pt x βx FiberPts.pt x' ; refl = Ξ» x β X.refl (FiberPts.pt x) ; trans = Ξ» p1 p2 β X.trans p1 p2 } where module X = Preorder X _βx_ = X._β_ module Y = Preorder Y record fibration {X : Preorder} {Y : Preorder} (f : X β¨ Y) : Set where module X = Preorder X module Y = Preorder Y _βx_ = X._β_ _βy_ = Y._β_ module f = _β¨_ f field -- A < B -> tm B -> tm A (downcast) pull : β (x : X.X) {y : Y.X} β (y βy app f x) β X.X -- the downcast is a lower bound -- dncast (A < B) N <= N pullLB : β {x : X.X} {y : Y.X} β (c : y βy app f x) β pull x c βx x -- the downcast is the *greatest* lower bound over a type at least as low -- Given N : B -- and M' : A' where A' <= A <= B -- and M' <= N over A' <= A <= B -- then M' <= dncast (A <= B) N over A' <= A pullGLB : β {x : X.X} {y : Y.X} {x' : X.X} β (c : y βy app f x) β (app f x' βy y) β (x' βx x) β x' βx pull x c opfibration : β {X Y} (f : X β¨ Y) β Set opfibration f = fibration (opF f) record GLTC : Setβ where field type : Preorder module type = Preorder type _βty_ = type._β_ field term : Preorder type-of : term β¨ type dncasts : fibration type-of upcasts : opfibration type-of -- need that the dncast of an upcast is the identity(!) -- projection : {!!} module term = Preorder term module type-of = _β¨_ type-of _βtm_ = term._β_ -- dynamic type field dyn : type.X dynT : β A β A βty dyn of-ty : type.X β Preorder of-ty A = Fiber type-of A -- errors field err : β A β Preorder.X (of-ty A) -- errβ₯ : β M β -- can we define err to be the least element of type dyn which then is then -- err <= up (M) so dn(err) <= dn(up(M)) -- function types field arr : type β¨ type β type arr' : type.X β type.X β type.X arr' A B = app (app arr A) B field lam : β {A B} β (of-ty A β of-ty B) β of-ty (arr' A B) -- can we *prove* that application preserves error, i.e., that (err{A -> B} N = err{B})? -- doubtful... seems like we need to add it in as an axiom, i.e., that the above is an iso of *pointed* preorders -- boolean types field bool : type.X -- this doesn't satisfy the UMP because -- there are terms that are not strict in their input (x |- x) if : β {A} β product (of-ty A) (of-ty A) β (of-ty bool β of-ty A) -- -- terms are more interesting because they are "clocked" -- term : type β K β Set -- _||_β¨_ββ_ : β {A B : type} β (A ββ B) β (k : K) β term A k β term B k β β -- -- reflexivity is "approximation-wise" -- reflβ : β {A}{M : β k β term A k} β (k : K) β reflβ || k β¨ (M k) ββ (M k) -- -- transitivity is only "in the limit" -- transβ : β {A B C}{M : β k β term A k}{N : β k β term B k}{P : β k β term C k} -- {AB : A ββ B}{BC : B ββ C} -- β (β k β AB || k β¨ (M k) ββ (N k)) -- β (β k β BC || k β¨ (N k) ββ (P k)) -- β β k β transβ AB BC || k β¨ (M k) ββ (P k) -- -- the above defines a kind of "guarded functor" ty : term -> type -- -- upcasts/downcasts ask that that functor be an/a opfibration/fibration -- up : β {A B} β A ββ B β β k β term A k β term B k -- dn : β {A B} β A ββ B β β k β term B k β term A k -- postulate -- βΈβ : Setβ β Setβ -- fix : (βΈβ π β π) β π -- ΞΈπ : βΈβ π β π -- infixl 30 _+_ -- data _+_ (A B : Set) : Set where -- inl_ : A β A + B -- inr_ : B β A + B -- record One : Set where -- constructor β¨β© -- Two : Set -- Two = One + One -- Lβ§ : Set β Set -- Lβ§ X = fix (Ξ» Lβ§X β One + X + ΞΈπ Lβ§X) -- dynβ§ : Set -- dynβ§ = fix Ξ» dynβ§ β Lβ§ ((Two + (ΞΈπ dynβ§ β ΞΈπ dynβ§))) record GTLC-CBV : Setβ where field type : Preorder valu : Preorder comp : Preorder ty-ofv : valu β¨ type ty-ofc : comp β¨ type module type = Preorder type val-of-ty : type.X β Preorder val-of-ty A = Fiber ty-ofv A comp-of-ty : type.X β Preorder comp-of-ty A = Fiber ty-ofc A field -- not quite right, need the rhs to be some kind of strict morphisms. -- should probably have a third sort of ev ctxts from A to B lett : β {A B} β (val-of-ty A β comp-of-ty B) β (comp-of-ty A β comp-of-ty B) upcasts : opfibration ty-ofv dncasts : fibration ty-ofc -- problem this doesn't imply that downcasts are linear, maybe we add this as a separate prop? -- something for projection property -- dynamic type dyn : type.X dynβ€ : β A β type β¨ A β dyn -- errors... -- functions arr : type β¨ type β type arr' : type.X β type.X β type.X arr' A B = app (app arr A) B field lam : β {A B} β (val-of-ty A β comp-of-ty B) β val-of-ty (arr' A B) -- bools bool : type.X if : β {A} β product (comp-of-ty A) (comp-of-ty A) β (val-of-ty bool β comp-of-ty A)