Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #2

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ec99a80
Basic Delay monotone predicate definition
ajrouvoet Oct 10, 2017
ef121bd
The partiality monad is also monad in the category of MPs
ajrouvoet Oct 10, 2017
4387c4b
Moving with the paper: upcastable references
ajrouvoet Oct 16, 2017
99e7d99
Moving with paper: add concatenation and prepend on paths
ajrouvoet Oct 16, 2017
daae329
Using do-notation in MJ/Semantics/Monadic
ajrouvoet Oct 19, 2017
8120a2c
Scratch files for cat development based on copumpkin's categories
ajrouvoet Oct 25, 2017
b85f71e
Add categories patch
ajrouvoet Oct 25, 2017
2afefcd
Proven that the product of MPs is an MP
ajrouvoet Oct 25, 2017
7f757be
Using copatterns for readability
ajrouvoet Oct 25, 2017
61aaad7
Proven product construction commutative
ajrouvoet Oct 25, 2017
07a01aa
Universality
ajrouvoet Oct 25, 2017
faba894
Commutativity for Products
ajrouvoet Oct 26, 2017
464f9e3
Lowerbounded forall quantification builds monotonicity
ajrouvoet Oct 26, 2017
2c8a7a8
Object mapping for monotone-state monad
ajrouvoet Oct 26, 2017
91d5fb3
Progress on formulating the monotone-state monad
ajrouvoet Oct 27, 2017
de90118
Monotone-state functor
ajrouvoet Oct 27, 2017
208e10d
Minor progress
ajrouvoet Oct 31, 2017
0eacdd8
Lots of prove readability improvements
ajrouvoet Oct 31, 2017
79b7ac3
Return is a natural transformation
ajrouvoet Nov 2, 2017
11d42f8
Closed one goal
ajrouvoet Nov 2, 2017
ecbe6d7
Sometimes you are in luck
ajrouvoet Nov 3, 2017
51c3bcc
Another one bites the dust
ajrouvoet Nov 3, 2017
bd4bcb5
Added goals for proving monadic strength
ajrouvoet Nov 3, 2017
e8621eb
Two more proofs down
ajrouvoet Nov 8, 2017
dfd2924
Left identity
ajrouvoet Nov 9, 2017
ea5285a
Associative
ajrouvoet Nov 9, 2017
79fb7a6
Transfoooorm
ajrouvoet Nov 9, 2017
c0a61b1
Prove some lemmas and rename StateT->PredicateT
ajrouvoet Nov 10, 2017
85d5de5
Added Delay setoid
ajrouvoet Nov 10, 2017
c593610
Delay is a functor in the category of ISetoids
ajrouvoet Nov 10, 2017
dafa4dd
Delay is a monad in the category ISetoids
ajrouvoet Nov 10, 2017
d1810e2
Add proof of monotone predicate monad identity law
ajrouvoet Nov 10, 2017
c1e8c5b
Add proof right identity Predicate mt
ajrouvoet Nov 14, 2017
27f29ef
Lemma about collapse
ajrouvoet Nov 14, 2017
88d242a
Simplified some proofs
ajrouvoet Nov 15, 2017
9d7f8d9
Add wip formalization of category of Cofes
ajrouvoet Nov 16, 2017
9f9bf16
Cofes as Ofes with a side-condition
ajrouvoet Nov 16, 2017
f64ad52
Add missing Ofe formalization
ajrouvoet Nov 16, 2017
7161b5a
Added Δ definition and goals for "later"
ajrouvoet Nov 16, 2017
748bdb5
Later is an endofunctor of Ofe
ajrouvoet Nov 20, 2017
4425b52
Proof that morphisms built on cofes give rise to cofes
ajrouvoet Nov 20, 2017
6e3f890
Minor improvement on def. of Cofes
ajrouvoet Nov 20, 2017
175f47c
Later is a Cofe
ajrouvoet Nov 20, 2017
edb7100
Removed some junk
ajrouvoet Nov 20, 2017
dad0dc1
Contractive functions
ajrouvoet Nov 21, 2017
3a8aa2b
Got rid of unnecessary setoid equality
ajrouvoet Nov 21, 2017
34060f3
Fixed points of contractive functions
ajrouvoet Nov 21, 2017
ebc4354
Ofe is monoidal
ajrouvoet Nov 21, 2017
3b3963d
Every category of functors has products if its codomain has products
ajrouvoet Nov 22, 2017
d8fdb46
Everything has products
ajrouvoet Nov 22, 2017
26a703b
Generalized predicates over Setoids to Ofes
ajrouvoet Nov 22, 2017
07b3e69
Monotone closure of predicates
ajrouvoet Nov 23, 2017
572ed8c
Moved cofes and monotone predicates into ofes modules
ajrouvoet Nov 23, 2017
39bc464
Exponentials for OFEs and fueled functions are OFEs
ajrouvoet Dec 6, 2017
70d07fd
Important properties of ►
ajrouvoet Dec 7, 2017
63da4f4
Merge branch 'master' into categorical
ajrouvoet Dec 7, 2017
8fd0ba5
+ ⊤⇨A≅A : (⊤.⊤ ⇨ A) ≅ A
ajrouvoet Dec 7, 2017
91287f6
Fixed the fixpoint combinator
ajrouvoet Dec 7, 2017
ab26a07
Useful properties
ajrouvoet Dec 7, 2017
7674cf7
StepIndexed ofes are complete
ajrouvoet Dec 7, 2017
7fe1785
+ Coproducts on Ofes
ajrouvoet Dec 8, 2017
a034a8c
Some properties and an example using partiality
ajrouvoet Dec 8, 2017
55e812c
Add proof that StepIndexed is a functor from ISetoids to Ofes
ajrouvoet Dec 11, 2017
3bbc472
Rewrote Arith example in terms of eliminator instead of destructor
ajrouvoet Dec 11, 2017
1a274d3
Some comments
ajrouvoet Dec 11, 2017
8bb257f
Moved some general properties from Arith
ajrouvoet Dec 11, 2017
c8617e3
Add BoolNum example demonstrating typed syntax
ajrouvoet Dec 12, 2017
78024dd
Added compilation target
ajrouvoet Feb 26, 2018
a397c2b
Cleanup example extraction
ajrouvoet Feb 26, 2018
676af68
Update libs and change MJ binops from Agda function to syntax
ajrouvoet Feb 27, 2018
5f34ade
Generalize the MJ semantics over any suitable monad
ajrouvoet Mar 8, 2018
78a7bad
Merge branch 'master' into sugar
ajrouvoet Mar 8, 2018
5b2cb20
Trashing some deprecated code
ajrouvoet Mar 8, 2018
09618d8
Merge branch 'categorical'
ajrouvoet Mar 8, 2018
7b0f1cc
Fix build and add nix build
ajrouvoet Mar 9, 2018
28e6dbe
Update the README: Agda 2.6.0 is required for the syntactic sugar
ajrouvoet Mar 9, 2018
f6769dd
Merge branch 'master' into develop
ajrouvoet Mar 9, 2018
d7efc37
Unphony the libraries for safer builds
ajrouvoet Mar 9, 2018
6bbdda9
Merge branch 'master' into develop
ajrouvoet Mar 9, 2018
3b9cc0f
Abstract the MJ semantics over an arbitrary monad
ajrouvoet Mar 9, 2018
da382dd
Update to Agda 2.5.4
ajrouvoet Aug 13, 2018
6cf48bf
Everything that compiles at 2.5.4
ajrouvoet Aug 13, 2018
5c2f057
Fix for 2.5.4
ajrouvoet Aug 13, 2018
82bd9c6
Uncomment imports that are very slow to typecheck in Readme
ajrouvoet Aug 13, 2018
aa37b2b
Minor updates to stdlib++
ajrouvoet Aug 14, 2018
05ff9e8
Add instance argument to help Agda 2.5.4.1
ajrouvoet Aug 15, 2018
c751dad
Remove stale implicit argument
ajrouvoet Aug 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agda-lib
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include:
./src/
./lib/stdlib/src/
./lib/stdlib++/src/
./lib/categories
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs/
hs/
*.agdai
.#*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/stdlib"]
path = lib/stdlib
url = https://github.com/agda/agda-stdlib
[submodule "lib/categories"]
path = lib/categories
url = https://github.com/copumpkin/categories.git
17 changes: 11 additions & 6 deletions Readme.agda
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
A rendered and linked version of this readme can be found here:
- https://metaborg.github.io/mj.agda/

This development has been tested against Agda 2.5.3 (and should also compile
with 2.6.0). If you have this installed, you should simply be able to run
The current development uses do-notation syntactic sugar
that is now part of Agda 2.5.4+ and will not compile with earlier versions.
The POPL paper does *not* use do-notation; you may want to download the
mj-1.0.0-popl18 release if you want a version compatible with the
paper and Agda 2.5.3.

If you have the right version of Agda installed, you should be able to run
`make` in the project root. This will checkout the two dependencies in
`./lib/` first and then build this `./Readme.agda` which serves as the main
entrypoint to the development.
Expand All @@ -22,7 +27,7 @@
for it. The html docs are syntax-highlighted and you can click
references to navigate to their definitions.

There are some minor differences between the Agda code used in the
There are some differences between the Agda code used in the
paper and this mechanization. One general (but minor) discrepancy
is that the definitions in the paper are typed in a manner that is
not universe polymorphic. However, the development makes extensive
Expand Down Expand Up @@ -223,9 +228,9 @@ open import Experiments.Infer
point-free style.
-}

open import Experiments.Category
open import Experiments.StrongMonad
open import Experiments.STLCRefPointfree
-- open import Experiments.Category
-- open import Experiments.StrongMonad
-- open import Experiments.STLCRefPointfree

{-
We briefly outline how these experiments relate to our paper.
Expand Down
23 changes: 23 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
pkgs ? (import <nixpkgs> {})
}:

let
# get nixplus
nixplus = import (pkgs.fetchgit {
url = https://gitlab.ewi.tudelft.nl/aj.rouvoet/nixplus.nix.git;
sha256 = "0zla8sf6k1n0ggb2h416n0x4ganjr3lnrz4mv5blsfyakjhrrxha";
rev = "e9d6d27e37e88d318dd5963b1751482c292ce36f";
});

in nixplus.stdenv.mkDerivation rec {
version = "1.1.0";
name = "mj.agda-${version}";
src = ./.;

buildInputs = with nixplus; [
git
agdaPackages.Agda.v2_5_4
];
}

1 change: 1 addition & 0 deletions lib/categories
Submodule categories added at 00e385
2 changes: 1 addition & 1 deletion lib/stdlib
Submodule stdlib updated 222 files
2 changes: 1 addition & 1 deletion lib/stdlib++
16 changes: 13 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
VERSION = 1.0.0-SNAPSHOT
AGDA_OPTS = --verbose=2
AGDA = agda $(AGDA_OPTS)

# some library paths
docs/%.html: %.agda
agda $< --html --html-dir=./docs/
$(AGDA) $< --html --html-dir=./docs/

%.agdai: %.agda
agda $<
$(AGDA) $<

.PHONY: hs/%
hs/%: src/%.agda
$(AGDA) --compile --compile-dir hs $<

all: lib Readme.agdai

Expand All @@ -19,7 +25,11 @@ docs: lib docs/Readme.html
cp docs/Readme.html docs/index.html

### libraries
lib: lib/stdlib/.git lib/stdlib++/.git
lib: lib/stdlib/.git lib/stdlib++/.git lib/categories/.git

lib/categories/.git:
git submodule update --init lib/categories
cd lib/categories

lib/stdlib++/.git:
git submodule update --init lib/stdlib++
Expand Down
88 changes: 88 additions & 0 deletions src/Categorical/Examples/Arith.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module Categorical.Examples.Arith where
{-
This example demonstrates how the *later* guard and fueled functions
can be used to build a definitional interpreter for a simple
arithmetic language.

This example does not involve intrinsically typed syntax or state.
It also doesn't necessitate fuel, because we could build the fixpoint in Agda;
but we do not allow that escape here.
-}

open import Level using () renaming (zero to lz)
open import Data.Nat as Nat using (ℕ)
open import Relation.Binary.PropositionalEquality using () renaming (refl to ≣-refl)

open import Categories.Category
open import Categories.Support.Equivalence

open import Categorical.Ofe
open import Categorical.Ofe.Cofe renaming (_⇨_ to _⇨-cofe_)
open import Categorical.Ofe.Products
open import Categorical.Ofe.Exponentials
open import Categorical.Ofe.Later
open import Categorical.Ofe.StepIndexed
open import Categorical.Ofe.Properties

-- we specialize here to ofes at universe level zero;
-- all our types and such fit in there
Cat = Ofes {lz}{lz}{lz}

open import Categories.Object.Exponential Cat
open import Categories.Object.Exponentiating Cat binary-products
open import Categories.Object.BinaryProducts Cat
open import Categories.Support.SetoidFunctions as SF using () renaming (→-to-⟶ to lift)

open Category Cat
open BinaryProducts binary-products

private
data Exp-set : Set where
num : ℕ → Exp-set
add : Exp-set → Exp-set → Exp-set

-- our values are just the natural numbers
Val = set→setoid ℕ

-- lift expressions to Ofe trivially
Exp = Δ⁺ Exp-set

module Elim (A : Ofe lz lz lz) where

Rec = (Exp ⇨ A)

-- eliminator of the Exp type
elim : (Rec ×-ofe (Δ⁺ ℕ)) ⇒ A →
(Rec ×-ofe (Exp ×-ofe Exp)) ⇒ A →
(Rec ×-ofe Exp) ⇒ A
_⟨$⟩_ (elim f g) (rec , num n) = f ⟨$⟩ (rec , n)
_⟨$⟩_ (elim f g) (rec , add e₁ e₂) = g ⟨$⟩ (rec , e₁ , e₂)
cong (elim f g) {x = rec , num _} (eq , ≣-refl) = cong f (eq , ≣-refl)
cong (elim f g) {x = rec , add _ _} (eq , ≣-refl) = cong g (eq , ≣-refl , ≣-refl)

-- Make the syntax of manipulating exponentiating available
module _ {X : Obj} where
open Exponentiating record { exponential = λ {A} → exp A X } public

Eval = Exp ⇨ ⇀ Val

eval-arith : ⊤ ⇒ Eval
eval-arith = μ (Exp ⇨-cofe (⇀-cofe Val)) eval' (⇨-const (⇀-inhabited Val))
where
case-num : (Eval × Δ⁺ ℕ) ⇒ ⇀ Val
case-num = fuel SF.id ∘ π₂ {A = Eval}

case-add : (Eval × (Exp × Exp)) ⇒ ⇀ Val
case-add =
{!!} -- add values
∘ _⁂_ {C = Eval × Exp} eval eval -- recursively evaluate the sub-expressions
∘ ×-distrib-× {A = Eval}{B = Exp}{C = Exp} -- fiddling with arguments

eval' : Ofes [ ► Eval , Eval ]
eval' =
λ-abs _ ( -- building a function
Elim.elim (⇀ Val) -- eliminate the two expression-cases
case-num
case-add
∘ first {C = Exp} rec-unfold -- build the recursor
)
114 changes: 114 additions & 0 deletions src/Categorical/Examples/BoolNum.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{-# OPTIONS --show-implicit #-}
module Categorical.Examples.BoolNum where
{-
This example builds on Categorical.Examples.Arith

We add a type bool and the corresponding value and expressions.
To ensure soundness-by-construction we type the expression and value syntax.

The interpreter structure remains the same, but the expression-elimination
is more involved.
-}

open import Level using () renaming (zero to lz)
open import Data.Nat as Nat using (ℕ)
open import Relation.Binary.PropositionalEquality using () renaming (refl to ≣-refl)

open import Categories.Category
open import Categories.Support.Equivalence

open import Categorical.Ofe
open import Categorical.Ofe.Cofe renaming (_⇨_ to _⇨-cofe_)
open import Categorical.Ofe.Products
open import Categorical.Ofe.Exponentials
open import Categorical.Ofe.Later
open import Categorical.Ofe.StepIndexed
open import Categorical.Ofe.Properties
open import Categorical.Ofe.Predicates
open import Categorical.Ofe.Predicates.Properties
open import Categorical.Ofe.Predicates.Closures

-- we specialize here to ofes at universe level zero;
-- all our types and such fit in there
Cat = Ofes {lz}{lz}{lz}

open import Categories.Object.Exponential Cat
open import Categories.Object.Exponentiating Cat binary-products
open import Categories.Object.BinaryProducts Cat
open import Categories.Support.SetoidFunctions as SF using () renaming (→-to-⟶ to lift)

open Category Cat
open BinaryProducts binary-products

data Type : Set where
bool : Type
int : Type

data Exp-set : Type → Set where
num : ℕ → Exp-set int
add : Exp-set int → Exp-set int → Exp-set int

data Val-set : Type → Set where
num : ℕ → Val-set int
true false : Val-set bool

-- our values are just the natural numbers
Val : Type → Setoid lz lz
Val a = set→setoid (Val-set a)

-- lift expressions to Ofe trivially
Exp : Type → Obj
Exp a = Δ⁺ (Exp-set a)

module Elim (A : Type → Obj) where

Rec = ∀[ Type ] λ a → (Exp a ⇨ A a)

-- eliminator of the Exp type
elim : (Rec ×-ofe (Δ⁺ ℕ)) ⇒ A int →
(Rec ×-ofe (Exp int ×-ofe Exp int)) ⇒ A int →
∀ {a} → (Rec ×-ofe (Exp a)) ⇒ A a
_⟨$⟩_ (elim f g) (rec , num n) = f ⟨$⟩ (rec , n)
_⟨$⟩_ (elim f g) (rec , add e₁ e₂) = g ⟨$⟩ (rec , e₁ , e₂)
cong (elim f g) {x = rec , num _} (eq , ≣-refl) = cong f (eq , ≣-refl)
cong (elim f g) {x = rec , add _ _} (eq , ≣-refl) = cong g (eq , ≣-refl , ≣-refl)

-- Make the syntax of manipulating exponentiating available
module _ {X : Obj} where
open Exponentiating record { exponential = λ {A} → exp A X } public

Eval = ∀[ Type ] λ a → Exp a ⇨ ⇀ (Val a)

eval-arith : ⊤ ⇒ Eval
eval-arith =
μ
(∀[ Type ]-cofe λ a → (Exp a ⇨-cofe (⇀-cofe Val a))) -- the type of the interpreter is cauchy-complete
eval-arith' -- interpreter with guarded recursor
(λ a → ⇨-const (⇀-inhabited (Val a))) -- initial element
where

-- generalizes the evaluation of an exponent
-- to the polymorphic exponent matching Eval.
eval' : ∀ {a} → Ofes [ Eval ×-ofe Exp a , ⇀ (Val a) ]
eval' {a} = eval ∘ first {C = Exp a} (∀-elim {A = λ a → (Exp a ⇨ (⇀ Val a))} a)

case-num : (Eval × Δ⁺ ℕ) ⇒ ⇀ (Val int)
case-num = fuel (lift num) ∘ π₂ {A = Eval}

case-add : (Eval × (Exp int × Exp int)) ⇒ ⇀ (Val int)
case-add =
{!!} -- add values
∘ _⁂_ {C = Eval × Exp int} eval' eval' -- recursively evaluate the sub-expressions
∘ ×-distrib-× {A = Eval}{B = Exp int}{C = Exp int} -- fiddling with arguments

eval-arith' : ► Eval ⇒ Eval
eval-arith' =
∀-intro (λ a →
λ-abs {Γ = ► Eval} (Exp a) (
Elim.elim (λ a → ⇀ Val a) case-num case-add
∘ first {A = ► Eval}{B = Eval}{C = Exp a} (
∀-intro (λ a → rec-unfold ∘ ∀-elim a)
∘ ►∀
)
)
)
14 changes: 14 additions & 0 deletions src/Categorical/Functor/Const.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Categorical.Functor.Const where

open import Categories.Category
open import Categories.Functor using (Functor)

const : ∀ {o ℓ e o' ℓ' e'}{D : Category o' ℓ' e'}{C : Category o ℓ e} → Category.Obj D → Functor C D
const {D = D} o = record
{ F₀ = λ _ → o
; F₁ = λ _ → Category.id D
; identity = refl
; homomorphism = λ {X} {Y} {Z} {f} {g} → sym (Category.identityˡ D)
; F-resp-≡ = λ x → refl
}
where open Category.Equiv D
Loading