├── .gitignore ├── doc ├── rulesUsual.sed ├── colour-science.pdf ├── rules2.sed ├── rules-motivation.sed ├── latexmk.config ├── commands.tex ├── lagda2tex ├── tools │ └── LiterateToRawAgda.hs ├── Makefile ├── models-cbn.agda ├── rules.sed ├── motivation.lagda ├── slides.tex ├── 2017-01-17.tex ├── usual.lagda ├── haskell │ └── Models.hs ├── main.bib └── sigplanconf.cls ├── models.pdf ├── slides.pdf ├── src ├── Syntax │ ├── MoggiML.agda │ ├── Context.agda │ ├── Core.agda │ ├── Type.agda │ ├── MoggiML │ │ ├── Type.agda │ │ ├── CPS.agda │ │ └── Calculus.agda │ ├── Core │ │ └── Examples.agda │ ├── Calculus.agda │ ├── Normal.agda │ ├── Context │ │ └── Core.agda │ └── Normal │ │ └── Weakening.agda ├── Semantics │ ├── Model │ │ └── Core.agda │ ├── Instances.agda │ ├── Model.agda │ ├── Syntactic │ │ ├── Instances.agda │ │ └── Specification.agda │ ├── Environment.agda │ ├── Embedding.agda │ ├── CPS │ │ ├── CBN.agda │ │ └── CBV.agda │ ├── Examples.agda │ ├── Specification.agda │ ├── NormalisationByEvaluation │ │ ├── βιξ.agda │ │ ├── βιξη.agda │ │ └── βι.agda │ ├── Environment │ │ └── Core.agda │ └── Printing.agda ├── Syntax.agda ├── Properties │ ├── Relation │ │ ├── Printing.agda │ │ └── βιξη.agda │ ├── Synchronisable │ │ ├── Instances.agda │ │ └── Specification.agda │ ├── Fusable │ │ ├── Syntactic │ │ │ ├── Specification.agda │ │ │ └── Instances.agda │ │ ├── Specification.agda │ │ └── Instances.agda │ └── Relation.agda └── README.agda └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.agda~ 2 | *.agdai 3 | -------------------------------------------------------------------------------- /doc/rulesUsual.sed: -------------------------------------------------------------------------------- 1 | s/models\.//g 2 | -------------------------------------------------------------------------------- /models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gallais/type-scope-semantics/HEAD/models.pdf -------------------------------------------------------------------------------- /slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gallais/type-scope-semantics/HEAD/slides.pdf -------------------------------------------------------------------------------- /doc/colour-science.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gallais/type-scope-semantics/HEAD/doc/colour-science.pdf -------------------------------------------------------------------------------- /src/Syntax/MoggiML.agda: -------------------------------------------------------------------------------- 1 | module Syntax.MoggiML where 2 | 3 | open import Syntax.MoggiML.Type public 4 | open import Syntax.MoggiML.Calculus public 5 | 6 | -------------------------------------------------------------------------------- /doc/rules2.sed: -------------------------------------------------------------------------------- 1 | s/𝓔/\\mathcal\{E\}/g 2 | s/𝓜/\\mathcal\{M\}/g 3 | s/𝓢/\\mathcal\{S\}/g 4 | s/𝓒/\\mathcal\{C\}/g 5 | s/𝓥/\\mathcal\{V\}/g 6 | s/ε/\\varepsilon\{\}/g -------------------------------------------------------------------------------- /src/Syntax/Context.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Context Type where 2 | 3 | open import Syntax.Context.Core as CC hiding (Context) public 4 | 5 | Context = CC.Context Type 6 | -------------------------------------------------------------------------------- /src/Syntax/Core.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Core where 2 | 3 | open import Syntax.Type public 4 | open import Syntax.Context Type public 5 | open import Syntax.Calculus public 6 | -------------------------------------------------------------------------------- /src/Semantics/Model/Core.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Model.Core (Type : Set) where 2 | 3 | open import Level 4 | open import Syntax.Context 5 | 6 | Model : (ℓ : Level) → Set (suc ℓ) 7 | Model ℓ = Context Type → Type → Set ℓ 8 | 9 | -------------------------------------------------------------------------------- /doc/rules-motivation.sed: -------------------------------------------------------------------------------- 1 | s/\\AgdaSymbol{(∀} \\AgdaSymbol{\\{}\\AgdaBound{σ}\\AgdaSymbol{\\}} \\AgdaSymbol{→}/\\AgdaSymbol{(∀}\\AgdaBound{σ}\\AgdaSymbol{.}/g 2 | s/\\AgdaFunction{throwaway[a-z]*} \\AgdaSymbol{:} //g 3 | s/◆/\\blacklozenge{}/g -------------------------------------------------------------------------------- /src/Syntax.agda: -------------------------------------------------------------------------------- 1 | module Syntax where 2 | 3 | open import Syntax.Type public 4 | open import Syntax.Context Type public 5 | open import Syntax.Calculus public 6 | open import Syntax.Normal public 7 | open import Semantics.Syntactic.Instances public 8 | -------------------------------------------------------------------------------- /src/Syntax/Type.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Type where 2 | 3 | open import Data.Product 4 | open import Relation.Binary.PropositionalEquality 5 | 6 | infixr 20 _`→_ 7 | data Type : Set where 8 | `Unit : Type 9 | `Bool : Type 10 | _`→_ : (σ τ : Type) → Type 11 | 12 | `→-inj : {σ₁ τ₁ σ₂ τ₂ : Type} → σ₁ `→ τ₁ ≡ σ₂ `→ τ₂ → σ₁ ≡ σ₂ × τ₁ ≡ τ₂ 13 | `→-inj refl = refl , refl 14 | -------------------------------------------------------------------------------- /src/Properties/Relation/Printing.agda: -------------------------------------------------------------------------------- 1 | module Properties.Relation.Printing where 2 | 3 | open import Semantics.Printing 4 | open import Properties.Relation 5 | open import Function 6 | open import Relation.Binary.PropositionalEquality 7 | 8 | _≈_ : RModel _ Printer Printer 9 | _≈_ = mkRModel $ λ p q → ∀ {names names′} → 10 | names ≡ names′ → runPrinter p names ≡ runPrinter q names′ 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # type-scope-semantics 2 | A self-contained repository for the paper [Type and Scope Preserving Semantics](https://gallais.github.io/pdf/cpp2017.pdf) 3 | 4 | 5 | TypeChecking 6 | ============ 7 | 8 | To compile this project, you will need: 9 | 10 | - Agda version 2.5.4.2 (available on [Hackage](http://hackage.haskell.org/package/Agda-2.5.4.2)) 11 | - Agda's standard library version 0.17 (available on [github](https://codeload.github.com/agda/agda-stdlib/tar.gz/v0.17)) 12 | 13 | -------------------------------------------------------------------------------- /src/Syntax/MoggiML/Type.agda: -------------------------------------------------------------------------------- 1 | module Syntax.MoggiML.Type where 2 | 3 | open import Data.Product 4 | open import Relation.Binary.PropositionalEquality 5 | 6 | infixr 20 _`→#_ #_ 7 | data Type : Set where 8 | `Unit : Type 9 | `Bool : Type 10 | _`→#_ : (σ τ : Type) → Type 11 | #_ : Type → Type 12 | 13 | `→-inj : {σ₁ τ₁ σ₂ τ₂ : Type} → (σ₁ `→# τ₁) ≡ (σ₂ `→# τ₂) → σ₁ ≡ σ₂ × τ₁ ≡ τ₂ 14 | `→-inj refl = refl , refl 15 | 16 | #-inj : {σ τ : Type} → # σ ≡ # τ → σ ≡ τ 17 | #-inj refl = refl 18 | -------------------------------------------------------------------------------- /doc/latexmk.config: -------------------------------------------------------------------------------- 1 | # Set pdf viewer as in 'start VIEWER' 2 | $pdf_previewer = 'mupdf'; 3 | 4 | # If zero, check for a previously running previewer on the same file and update it. If nonzero, always start a new previewer. 5 | $new_viewer_always = 0; 6 | 7 | # How to make the PDF viewer update its display when the PDF file changes. See the man page for a description of each method. 8 | $pdf_update_method = 2; 9 | 10 | # When PDF update method 2 is used, the number of the Unix signal to send 11 | $pdf_update_signal = 'SIGHUP'; -------------------------------------------------------------------------------- /src/Semantics/Instances.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Instances where 2 | 3 | open import Semantics.Embedding public 4 | open import Semantics.Syntactic.Instances public 5 | open import Semantics.Printing public 6 | open import Semantics.NormalisationByEvaluation.βιξη 7 | open import Semantics.NormalisationByEvaluation.βιξ 8 | open import Semantics.NormalisationByEvaluation.βι 9 | 10 | module βιξη = Semantics.NormalisationByEvaluation.βιξη 11 | module βιξ = Semantics.NormalisationByEvaluation.βιξ 12 | module βι = Semantics.NormalisationByEvaluation.βι 13 | -------------------------------------------------------------------------------- /doc/commands.tex: -------------------------------------------------------------------------------- 1 | %%%%%%%%%% AGDA ALIASES 2 | 3 | \newcommand{\APT}{\AgdaPrimitiveType} 4 | \newcommand{\AK}{\AgdaKeyword} 5 | \newcommand{\AM}{\AgdaModule} 6 | \newcommand{\AS}{\AgdaSymbol} 7 | \newcommand{\AStr}{\AgdaString} 8 | \newcommand{\AN}{\AgdaNumber} 9 | \newcommand{\AD}{\AgdaDatatype} 10 | \newcommand{\AF}{\AgdaFunction} 11 | \newcommand{\AR}{\AgdaRecord} 12 | \newcommand{\ARF}{\AgdaField} 13 | \newcommand{\AB}{\AgdaBound} 14 | \newcommand{\AIC}{\AgdaInductiveConstructor} 15 | 16 | \newcommand{\model}{$\mathit{𝓜}^{Γ}_{σ}$} 17 | \newcommand{\anchor}[1]{\noindent\textbf{[#1]}} 18 | -------------------------------------------------------------------------------- /src/Semantics/Model.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Model where 2 | 3 | open import Level as L using (Level ; _⊔_) public 4 | open import Syntax.Core 5 | open import Syntax.Normal 6 | open import Semantics.Model.Core Type public 7 | 8 | Applicative : {ℓ : Level} → Model ℓ → Set ℓ 9 | Applicative 𝓜 = {Γ : Context} {σ τ : Type} → 𝓜 Γ (σ `→ τ) → 𝓜 Γ σ → 𝓜 Γ τ 10 | 11 | Reify : {ℓ : Level} → (Type → Set) → Model ℓ → Set ℓ 12 | Reify R 𝓜 = {Γ : Context} (σ : Type) → 𝓜 Γ σ → Γ ⊢[ R ]^nf σ 13 | 14 | Reflect : {ℓ : Level} → (Type → Set) → Model ℓ → Set ℓ 15 | Reflect R 𝓔 = {Γ : Context} (σ : Type) → Γ ⊢[ R ]^ne σ → 𝓔 Γ σ 16 | -------------------------------------------------------------------------------- /src/Syntax/Core/Examples.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Core.Examples where 2 | 3 | open import Syntax.Core 4 | 5 | VAR0 : {Γ : Context} {σ : Type} → (Γ ∙ σ) ⊢ σ 6 | VAR0 = `var zero 7 | 8 | APP : {Γ : Context} {σ τ : Type} → (Γ ∙ (σ `→ τ) ∙ σ) ⊢ τ 9 | APP = `var (1+ zero) `$ `var zero 10 | 11 | ID : {Γ : Context} {σ : Type} → Γ ⊢ (σ `→ σ) 12 | ID = `λ VAR0 13 | 14 | TRUE : {Γ : Context} {σ τ : Type} → Γ ⊢ (σ `→ τ `→ σ) 15 | TRUE = `λ (`λ (`var (1+ zero))) 16 | 17 | FALSE : {Γ : Context} {σ τ : Type} → Γ ⊢ (σ `→ τ `→ τ) 18 | FALSE = `λ ID 19 | 20 | IFTE : {Γ : Context} {σ : Type} → Γ ⊢ (`Bool `→ (σ `→ σ `→ σ)) 21 | IFTE = `λ (`ifte (`var zero) TRUE FALSE) 22 | 23 | THUNK : {Γ : Context} {σ : Type} → Γ ⊢ (σ `→ (`Unit `→ σ)) 24 | THUNK = TRUE 25 | 26 | FORCE : {Γ : Context} {σ : Type} → Γ ⊢ ((`Unit `→ σ) `→ σ) 27 | FORCE = `λ (`var zero `$ `⟨⟩) 28 | 29 | ID' : {Γ : Context} {σ : Type} → Γ ⊢ (σ `→ σ) 30 | ID' = FORCE `$ (THUNK `$ ID) 31 | -------------------------------------------------------------------------------- /doc/lagda2tex: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | STDLIB=~/languages/agda/libs/agda-stdlib/src/ 4 | DIRECTORY=$( dirname "$1" ) 5 | TARGET=$( basename "$1" .lagda ) 6 | 7 | # Move to the directory 8 | cd "$DIRECTORY" 9 | # Compute the checksum of the target 10 | CHECK=`md5sum "$TARGET".lagda | awk '{ print $1 }'` 11 | # If the hash file does not exist, create a dummy one 12 | if [ ! -f "$TARGET".hash ]; then 13 | echo 0 > "$TARGET".hash 14 | fi 15 | # If the tex file hasn't been generated yet or if the 16 | # file has changed, then (re)generate it. 17 | if [ ! -f latex/"$TARGET".tex ] || [ $CHECK != `cat "$TARGET".hash` ]; then 18 | echo REGENERATE: "$DIRECTORY"/"$TARGET".tex 19 | agda -i . -i "$STDLIB" --latex "$TARGET".lagda > "$TARGET".log 20 | else 21 | echo FROM CACHE: "$DIRECTORY"/"$TARGET".tex 22 | fi 23 | echo "$CHECK" > "$TARGET".hash 24 | # Go back to the root directory and copy the generated tex 25 | cd - > /dev/null 26 | mkdir -p __build/"$DIRECTORY" 27 | cp "$DIRECTORY"/latex/"$TARGET".tex __build/"$DIRECTORY"/ 28 | -------------------------------------------------------------------------------- /doc/tools/LiterateToRawAgda.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | 3 | module Main where 4 | 5 | import Prelude as P 6 | import Data.Text as T 7 | import Data.Text.IO as TIO 8 | import System.FilePath 9 | import System.Environment 10 | 11 | altName :: String 12 | altName = "-raw" 13 | 14 | cleanup :: Text -> Text 15 | cleanup = T.unlines 16 | . P.dropWhile (T.null . T.filter (/= ' ')) 17 | . P.concatMap T.lines 18 | . fmap (P.head . splitOn "\\end{code}") 19 | . P.tail 20 | . splitOn "\\begin{code}" 21 | 22 | alterName :: Text -> Text 23 | alterName txt = 24 | let (modName, whereRest) = T.breakOn "where" txt 25 | (mod , name) = T.breakOnEnd "module" modName 26 | in T.concat [ mod, stripEnd name, T.pack altName, " ", whereRest ] 27 | 28 | main :: IO () 29 | main = do 30 | (fp : _) <- getArgs 31 | cleanedUp <- alterName . cleanup <$> TIO.readFile fp 32 | let (name, _) = splitExtension fp 33 | TIO.writeFile (name ++ altName ++ ".agda") cleanedUp 34 | -------------------------------------------------------------------------------- /src/Semantics/Syntactic/Instances.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Syntactic.Instances where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Environment 5 | open import Semantics.Syntactic.Specification 6 | 7 | -- We are, one more, using copatterns to prevent too much unfolding. 8 | SyntacticRenaming : Syntactic _∋_ 9 | Syntactic.embed SyntacticRenaming = refl 10 | Syntactic.wk SyntacticRenaming = wk^∋ 11 | Syntactic.⟦var⟧ SyntacticRenaming = `var 12 | 13 | 𝓢^Renaming = Fundamental.syntactic SyntacticRenaming 14 | 15 | rename : Weakening _⊢_ 16 | rename ren t = Fundamental.lemma SyntacticRenaming t ren 17 | 18 | SyntacticSubstitution : Syntactic _⊢_ 19 | Syntactic.embed SyntacticSubstitution = pack `var 20 | Syntactic.wk SyntacticSubstitution = rename 21 | Syntactic.⟦var⟧ SyntacticSubstitution = λ t → t 22 | 23 | 𝓢^Substitution = Fundamental.syntactic SyntacticSubstitution 24 | 25 | substitute : {Γ Δ : Context} {σ : Type} → Γ ⊢ σ → Var Γ ⇒[ _⊢_ ] Δ → Δ ⊢ σ 26 | substitute = Fundamental.lemma SyntacticSubstitution 27 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | STDLIB=~/languages/agda/libs/agda-stdlib-0.12/src/ 2 | SED=sed 3 | PAPER=models 4 | AUXILIARY=usual 5 | SLIDES=2017-01-17 6 | 7 | 8 | all: finish 9 | 10 | prepare: 11 | mkdir -p latex/ 12 | # rm -f latex/$(SLIDES).* 13 | cp *.tex *.cls *.bib *.sed *.config latex/ 14 | 15 | paper-lagda: 16 | ./lagda2tex motivation.lagda 17 | ./lagda2tex $(PAPER).lagda 18 | 19 | paper: prepare paper-lagda 20 | cd latex && ${SED} -f rules.sed -f rules2.sed -i $(PAPER).tex && ${SED} -f rules-motivation.sed -f rules.sed -f rules2.sed -i motivation.tex && \ 21 | latexmk -bibtex -pdf -e '$$pdflatex=q/xelatex %O %S/' $(PAPER).tex && cd .. 22 | 23 | auxiliary: 24 | ./lagda2tex $(AUXILIARY).lagda 25 | sed -f rulesUsual.sed -f rules.sed -f rules2.sed -i latex/$(AUXILIARY).tex 26 | 27 | slides: prepare auxiliary paper-lagda 28 | cd latex && ${SED} -f rules.sed -f rules2.sed -i $(SLIDES).tex -i $(AUXILIARY).tex $(PAPER).tex && \ 29 | latexmk -bibtex -pdf -e '$$pdflatex=q/xelatex %O %S/' $(SLIDES).tex 30 | ln -sf latex/${SLIDES}.pdf . 31 | 32 | finish: paper auxiliary slides 33 | xdotool search --class mupdf key --window %@ r > /dev/null 2>&1 34 | clean: 35 | rm -f *.agdai 36 | rm -rf latex/ 37 | -------------------------------------------------------------------------------- /src/Syntax/Calculus.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Calculus where 2 | 3 | open import Syntax.Type 4 | open import Syntax.Context Type 5 | 6 | -- The calculus is defined in a well-scoped and well-typed 7 | -- manner using an inductive family. A term effectively 8 | -- correponds to a derivation in the sequent calculus. 9 | 10 | -- Nota Bene: there are TWO proofs of Γ ⊢ `Bool corresponding 11 | -- to true and false respectively. 12 | 13 | infix 5 _⊢_ 14 | infixl 5 _`$_ 15 | data _⊢_ (Γ : Context) : (σ : Type) → Set where 16 | 17 | `var : {σ : Type} → 18 | 19 | σ ∈ Γ → 20 | -------------- 21 | Γ ⊢ σ 22 | 23 | _`$_ : {σ τ : Type} → 24 | 25 | Γ ⊢ (σ `→ τ) → Γ ⊢ σ → 26 | -------------------------- 27 | Γ ⊢ τ 28 | 29 | `λ : {σ τ : Type} → 30 | 31 | (Γ ∙ σ) ⊢ τ → 32 | ---------------- 33 | Γ ⊢ (σ `→ τ) 34 | 35 | `⟨⟩ : 36 | ------------- 37 | Γ ⊢ `Unit 38 | 39 | `tt `ff : 40 | ------------- 41 | Γ ⊢ `Bool 42 | 43 | `ifte : {σ : Type} → 44 | 45 | Γ ⊢ `Bool → Γ ⊢ σ → Γ ⊢ σ → 46 | ------------------------------ 47 | Γ ⊢ σ 48 | -------------------------------------------------------------------------------- /src/Semantics/Syntactic/Specification.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Syntactic.Specification where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment 6 | open import Semantics.Specification as Semantics hiding (module Fundamental) 7 | 8 | record Syntactic {ℓ : Level} (𝓔 : Model ℓ) : Set ℓ where 9 | field embed : {Γ : Context} → Var Γ ⇒[ 𝓔 ] Γ 10 | wk : Weakening 𝓔 11 | ⟦var⟧ : {Γ : Context} {σ : Type} → 𝓔 Γ σ → Γ ⊢ σ 12 | 13 | module Fundamental {ℓ : Level} {𝓔 : Model ℓ} (𝓢 : Syntactic 𝓔) where 14 | 15 | open Syntactic 𝓢 16 | 17 | -- Using copatterns here guarantees that these things are not unfolded 18 | -- when normalising goals thus making them more readable. 19 | syntactic : Semantics 𝓔 _⊢_ 20 | Semantics.wk syntactic = wk 21 | Semantics.embed syntactic = embed 22 | Semantics.⟦var⟧ syntactic = ⟦var⟧ 23 | Semantics.⟦λ⟧ syntactic = λ t → `λ (t extend (lookup embed zero)) 24 | Semantics._⟦$⟧_ syntactic = _`$_ 25 | Semantics.⟦⟨⟩⟧ syntactic = `⟨⟩ 26 | Semantics.⟦tt⟧ syntactic = `tt 27 | Semantics.⟦ff⟧ syntactic = `ff 28 | Semantics.⟦ifte⟧ syntactic = `ifte 29 | 30 | lemma : {Δ Γ : Context} {σ : Type} → Γ ⊢ σ → Var Γ ⇒[ 𝓔 ] Δ → Δ ⊢ σ 31 | lemma = Semantics.Fundamental.lemma syntactic 32 | -------------------------------------------------------------------------------- /src/Semantics/Environment.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Environment where 2 | 3 | open import Syntax.Core hiding (_<$>_) 4 | open import Semantics.Model 5 | open import Semantics.Environment.Core as EC hiding (Var_⇒[_]_ ; Weakening) public 6 | 7 | Var_⇒[_]_ = EC.Var_⇒[_]_ {Type} 8 | Weakening = EC.Weakening Type 9 | 10 | -- Parallel substitutions are quite evidently environments: 11 | Substitution : Context → Context → Set 12 | Substitution Γ Δ = Var Γ ⇒[ _⊢_ ] Δ 13 | 14 | -- We can naturally define simple combinators for the empty 15 | -- environment and the extension of an existing environment 16 | -- with an extra value. 17 | 18 | `ε : {ℓ : Level} {Δ : Context} {𝓔 : Model ℓ} → Var ε ⇒[ 𝓔 ] Δ 19 | lookup `ε () 20 | 21 | infixl 10 _`∙_ 22 | _`∙_ : {ℓ : Level} {Γ Δ : Context} {𝓔 : Model ℓ} {σ : Type} → 23 | Var Γ ⇒[ 𝓔 ] Δ → 𝓔 Δ σ → Var (Γ ∙ σ) ⇒[ 𝓔 ] Δ 24 | lookup (ρ `∙ s) zero = s 25 | lookup (ρ `∙ s) (1+ n) = lookup ρ n 26 | 27 | -- If values in a model can be weakened so can an environment 28 | -- of such values 29 | 30 | wk[_] : {ℓ : Level} {Δ : Context} {𝓔 : Model ℓ} (wk : Weakening 𝓔) 31 | {Γ Θ : Context} → Renaming Δ Θ → Var Γ ⇒[ 𝓔 ] Δ → Var Γ ⇒[ 𝓔 ] Θ 32 | wk[ wk ] ren ρ = wk ren <$> ρ 33 | 34 | -- A weak form of transitivity: any environment may be pre-composed 35 | -- with a renaming to yield another environment. 36 | trans : {ℓ : Level} {Γ Δ Θ : Context} {𝓔 : Model ℓ} → 37 | Renaming Γ Δ → Var Δ ⇒[ 𝓔 ] Θ → Var Γ ⇒[ 𝓔 ] Θ 38 | trans ren env = lookup env <$> ren 39 | -------------------------------------------------------------------------------- /src/README.agda: -------------------------------------------------------------------------------- 1 | module README where 2 | 3 | -- Basic syntax 4 | open import Syntax.Type 5 | open import Syntax.Context 6 | open import Syntax.Calculus 7 | 8 | open import Syntax.Core.Examples 9 | 10 | -- Abstract presentation of the notion of Model 11 | open import Semantics.Model 12 | open import Semantics.Environment 13 | open import Semantics.Specification 14 | 15 | -- The simplest model probably: Embedding in Agda 16 | open import Semantics.Embedding 17 | 18 | -- Syntactic Models are very simple Models 19 | open import Semantics.Syntactic.Specification 20 | open import Semantics.Syntactic.Instances 21 | 22 | -- Conversion to CPS via Moggi's ML 23 | open import Semantics.CPS.CBV 24 | open import Semantics.CPS.CBN 25 | open import Syntax.MoggiML.CPS 26 | 27 | -- Monadic Model 28 | open import Semantics.Printing 29 | 30 | -- Normalisation by Evaluation goes through a Model 31 | open import Syntax.Normal 32 | open import Semantics.NormalisationByEvaluation.βιξη 33 | open import Semantics.NormalisationByEvaluation.βιξ 34 | open import Semantics.NormalisationByEvaluation.βι 35 | 36 | open import Semantics.Examples 37 | 38 | 39 | -- Properties 40 | open import Properties.Relation 41 | open import Properties.Relation.βιξη 42 | 43 | open import Properties.Synchronisable.Specification 44 | open import Properties.Synchronisable.Instances 45 | 46 | open import Properties.Fusable.Specification 47 | open import Properties.Fusable.Syntactic.Specification 48 | open import Properties.Fusable.Syntactic.Instances 49 | open import Properties.Fusable.Instances 50 | -------------------------------------------------------------------------------- /src/Semantics/Embedding.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Embedding where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment 6 | open import Semantics.Specification 7 | open import Data.Unit 8 | open import Data.Bool 9 | open import Data.Product 10 | open import Function 11 | 12 | type : Type → Set 13 | type `Unit = ⊤ 14 | type `Bool = Bool 15 | type (σ `→ τ) = type σ → type τ 16 | 17 | context : Context → Set 18 | context ε = ⊤ 19 | context (Γ ∙ σ) = context Γ × type σ 20 | 21 | assumption : ∀ {Γ σ} → σ ∈ Γ → context Γ → type σ 22 | assumption zero (_ , s) = s 23 | assumption (1+ v) (ρ , _) = assumption v ρ 24 | 25 | contra : ∀ {Γ Δ} → Renaming Γ Δ → context Δ → context Γ 26 | contra {ε} ren ρ = tt 27 | contra {Γ ∙ σ} ren ρ = contra (pack (lookup ren ∘ 1+_)) ρ 28 | , assumption (lookup ren zero) ρ 29 | 30 | Agda : Model _ 31 | Agda Γ σ = context Γ → type σ 32 | 33 | wk^Agda : Weakening Agda 34 | wk^Agda ren t = t ∘ contra ren 35 | 36 | Embedding : Semantics Agda Agda 37 | Semantics.wk Embedding = wk^Agda 38 | Semantics.embed Embedding = pack assumption 39 | Semantics.⟦var⟧ Embedding = id 40 | Semantics.⟦λ⟧ Embedding = λ r ρ v → r refl (const v) ρ 41 | Semantics._⟦$⟧_ Embedding = λ f t ρ → f ρ (t ρ) -- this is the S combinator! 42 | Semantics.⟦⟨⟩⟧ Embedding = const tt 43 | Semantics.⟦tt⟧ Embedding = const true 44 | Semantics.⟦ff⟧ Embedding = const false 45 | Semantics.⟦ifte⟧ Embedding = λ b l r ρ → (if b ρ then l else r) ρ 46 | 47 | eval' : Evaluation' Agda 48 | eval' = Fundamental.lemma' Embedding 49 | -------------------------------------------------------------------------------- /src/Syntax/MoggiML/CPS.agda: -------------------------------------------------------------------------------- 1 | module Syntax.MoggiML.CPS where 2 | 3 | open import Syntax as λC 4 | open import Syntax.MoggiML as ML 5 | open import Semantics.Environment using (extend ; step) 6 | open import Semantics.Syntactic.Instances using (rename) 7 | 8 | -- The continuation monad 9 | Cont : λC.Type → λC.Type → λC.Type 10 | Cont r σ = (σ `→ r) `→ r 11 | 12 | return : ∀ {Γ σ r} → Γ λC.⊢ σ → Γ λC.⊢ Cont r σ 13 | return t = `λ (`var zero `$ rename extend t) 14 | 15 | bind : ∀ {Γ σ τ r} → Γ λC.⊢ Cont r σ → Γ λC.⊢ (σ `→ Cont r τ) → Γ λC.⊢ Cont r τ 16 | bind m f = `λ {- k -} (rename extend m `$ `λ {- v:σ -} 17 | ((rename (step extend) f `$ `var zero) `$ `var (1+ zero))) 18 | 19 | -- Translation of ML types using the continuation monad to interpret the 20 | -- computational monad #_ 21 | 22 | CPS[_] : (r : λC.Type) (σ : ML.Type) → λC.Type 23 | #CPS[_] : (r : λC.Type) (σ : ML.Type) → λC.Type 24 | 25 | CPS[ r ] `Bool = `Bool 26 | CPS[ r ] `Unit = `Unit 27 | CPS[ r ] (σ `→# τ) = CPS[ r ] σ `→ #CPS[ r ] τ 28 | CPS[ r ] (# σ) = #CPS[ r ] σ 29 | 30 | #CPS[ r ] σ = Cont r (CPS[ r ] σ) 31 | 32 | -- From terms in moggi's ML to terms in the λC via the CPS monad 33 | 34 | cps : ∀ {Γ σ r} → Γ ML.⊢ σ → CPS[ r ] <$> Γ λC.⊢ CPS[ r ] σ 35 | cps (`var v) = `var (map CPS[ _ ] v) 36 | cps (f `$ t) = cps f `$ cps t 37 | cps (`λ t) = `λ (cps t) 38 | cps `⟨⟩ = `⟨⟩ 39 | cps `tt = `tt 40 | cps `ff = `ff 41 | cps (`ifte b l r) = `ifte (cps b) (cps l) (cps r) 42 | cps (m `>>= f) = bind (cps m) (cps f) 43 | cps (`return t) = return (cps t) 44 | -------------------------------------------------------------------------------- /src/Syntax/Normal.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Normal where 2 | 3 | open import Syntax.Core 4 | 5 | infix 5 _⊢[_]^ne_ _⊢[_]^nf_ 6 | mutual 7 | 8 | data _⊢[_]^ne_ (Γ : Context) (R : Type → Set) (σ : Type) : Set where 9 | `var : (v : σ ∈ Γ) → Γ ⊢[ R ]^ne σ 10 | _`$_ : {τ : Type} (t : Γ ⊢[ R ]^ne τ `→ σ) (u : Γ ⊢[ R ]^nf τ) → Γ ⊢[ R ]^ne σ 11 | `ifte : (b : Γ ⊢[ R ]^ne `Bool) (l r : Γ ⊢[ R ]^nf σ) → Γ ⊢[ R ]^ne σ 12 | 13 | data _⊢[_]^nf_ (Γ : Context) (R : Type → Set) : (σ : Type) → Set where 14 | `neu : {σ : Type} (pr : R σ) (t : Γ ⊢[ R ]^ne σ) → Γ ⊢[ R ]^nf σ 15 | `⟨⟩ : Γ ⊢[ R ]^nf `Unit 16 | `tt : Γ ⊢[ R ]^nf `Bool 17 | `ff : Γ ⊢[ R ]^nf `Bool 18 | `λ : {σ τ : Type} (b : Γ ∙ σ ⊢[ R ]^nf τ) → Γ ⊢[ R ]^nf (σ `→ τ) 19 | 20 | Normalisation : (Type → Set) → Set 21 | Normalisation R = {Γ : Context} {σ : Type} → Γ ⊢ σ → Γ ⊢[ R ]^nf σ 22 | 23 | infix 5 _⊢^whne_ _⊢^whnf_ 24 | data _⊢^whne_ (Γ : Context) (σ : Type) : Set where 25 | `var : (v : σ ∈ Γ) → Γ ⊢^whne σ 26 | _`$_ : {τ : Type} (t : Γ ⊢^whne (τ `→ σ)) (u : Γ ⊢ τ) → Γ ⊢^whne σ 27 | `ifte : (b : Γ ⊢^whne `Bool) (l r : Γ ⊢ σ) → Γ ⊢^whne σ 28 | 29 | data _⊢^whnf_ (Γ : Context) : (σ : Type) → Set where 30 | `whne : {σ : Type} (t : Γ ⊢^whne σ) → Γ ⊢^whnf σ 31 | `⟨⟩ : Γ ⊢^whnf `Unit 32 | `tt `ff : Γ ⊢^whnf `Bool 33 | `λ : {σ τ : Type} (b : Γ ∙ σ ⊢ τ) → Γ ⊢^whnf (σ `→ τ) 34 | 35 | erase^whne : {Γ : Context} {σ : Type} (t : Γ ⊢^whne σ) → Γ ⊢ σ 36 | erase^whne (`var v) = `var v 37 | erase^whne (t `$ u) = erase^whne t `$ u 38 | erase^whne (`ifte t l r) = `ifte (erase^whne t) l r 39 | -------------------------------------------------------------------------------- /src/Semantics/CPS/CBN.agda: -------------------------------------------------------------------------------- 1 | module Semantics.CPS.CBN where 2 | 3 | open import Syntax as λC 4 | open import Syntax.MoggiML as ML 5 | open import Semantics.Model 6 | open import Semantics.Environment as Env hiding (refl) 7 | open import Semantics.Specification 8 | open import Data.Unit 9 | open import Data.Product 10 | open import Function 11 | open import Relation.Binary.PropositionalEquality 12 | 13 | mutual 14 | 15 | ⟦_⟧ : λC.Type → ML.Type 16 | ⟦ `Unit ⟧ = `Unit 17 | ⟦ `Bool ⟧ = `Bool 18 | ⟦ σ `→ τ ⟧ = #⟦ σ ⟧ `→# ⟦ τ ⟧ 19 | 20 | #⟦_⟧ : λC.Type → ML.Type 21 | #⟦ σ ⟧ = # ⟦ σ ⟧ 22 | 23 | mutual 24 | 25 | ⟦⟧-inj : ∀ σ τ → ⟦ σ ⟧ ≡ ⟦ τ ⟧ → σ ≡ τ 26 | ⟦⟧-inj `Unit `Unit eq = refl 27 | ⟦⟧-inj `Bool `Bool eq = refl 28 | ⟦⟧-inj (σ₁ `→ τ₁) (σ₂ `→ τ₂) eq = 29 | let (eqσ , eqτ) = ML.`→-inj eq 30 | in cong₂ _`→_ (#⟦⟧-inj σ₁ σ₂ eqσ) (⟦⟧-inj τ₁ τ₂ eqτ) 31 | ⟦⟧-inj `Unit `Bool () 32 | ⟦⟧-inj `Unit (_ `→ _) () 33 | ⟦⟧-inj `Bool `Unit () 34 | ⟦⟧-inj `Bool (_ `→ _) () 35 | ⟦⟧-inj (_ `→ _) `Unit () 36 | ⟦⟧-inj (_ `→ _) `Bool () 37 | 38 | #⟦⟧-inj : ∀ σ τ → #⟦ σ ⟧ ≡ #⟦ τ ⟧ → σ ≡ τ 39 | #⟦⟧-inj σ τ = ⟦⟧-inj σ τ ∘ #-inj 40 | 41 | Computation : Model _ 42 | Computation Γ σ = (#⟦_⟧ λC.<$> Γ) ML.⊢ #⟦ σ ⟧ 43 | 44 | CallByName : Semantics Computation Computation 45 | CallByName = record 46 | { wk = ML.wk^⊢ ∘ Env.map #⟦_⟧ #⟦⟧-inj 47 | ; embed = pack (`var ∘ λC.map #⟦_⟧) 48 | ; ⟦var⟧ = id 49 | ; ⟦λ⟧ = λ t → `return (`λ (t extend (`var zero))) 50 | ; _⟦$⟧_ = λ f t → f `>>= `λ (`var zero `$ ML.wk^⊢ extend t) 51 | ; ⟦⟨⟩⟧ = `return `⟨⟩ 52 | ; ⟦tt⟧ = `return `tt 53 | ; ⟦ff⟧ = `return `ff 54 | ; ⟦ifte⟧ = λ b l r → b `>>= `λ (`ifte (`var zero) (wk^⊢ extend l) (wk^⊢ extend r)) 55 | } 56 | -------------------------------------------------------------------------------- /src/Semantics/Examples.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Examples where 2 | 3 | open import Syntax hiding (_∋_) 4 | open import Syntax.Core.Examples 5 | open import Semantics.Environment hiding (refl) 6 | open import Data.Unit 7 | open import Data.Bool 8 | open import Function 9 | open import Relation.Binary.PropositionalEquality 10 | 11 | -- EMBEDDING 12 | 13 | open import Semantics.Embedding 14 | 15 | True : eval' (`ifte (ID `$ `ff) `ff `tt) tt ≡ true 16 | True = refl 17 | 18 | -- RENAMING & SUBSTITUTION 19 | 20 | open import Semantics.Syntactic.Instances 21 | 22 | substAPP : {σ : Type} → substitute APP (`ε `∙ FORCE `∙ (THUNK `$ ID)) 23 | ≡ (ε ⊢ σ `→ σ ∋ ID') 24 | substAPP = refl 25 | 26 | -- PRINTING 27 | open import Semantics.Printing 28 | 29 | printID : {σ : Type} → print (ε ⊢ σ `→ σ ∋ ID) ≡ "λa. a" 30 | printID = refl 31 | 32 | printTRUE : {σ τ : Type} → print (ε ⊢ σ `→ τ `→ σ ∋ TRUE) ≡ "λa. λb. a" 33 | printTRUE = refl 34 | 35 | printFALSE : {σ τ : Type} → print (ε ⊢ σ `→ τ `→ τ ∋ FALSE) ≡ "λa. λb. b" 36 | printFALSE = refl 37 | 38 | printIFTE : {σ : Type} → print (ε ⊢ `Bool `→ (σ `→ σ `→ σ) ∋ IFTE) 39 | ≡ "λa. if (a) then (λb. λc. b) else (λd. λe. e)" 40 | printIFTE = refl 41 | 42 | printTHUNK : {σ τ : Type} → print (ε ⊢ σ `→ `Unit `→ σ ∋ THUNK) ≡ "λa. λb. a" 43 | printTHUNK = refl 44 | 45 | printFORCE : {σ τ : Type} → print (ε ⊢ (`Unit `→ σ) `→ σ ∋ FORCE) ≡ "λa. a (⟨⟩)" 46 | printFORCE = refl 47 | 48 | printID' : print (ε ⊢ `Bool `→ `Bool ∋ ID') ≡ "λa. a (⟨⟩) (λb. λc. b (λd. d))" 49 | printID' = refl 50 | 51 | -- NORMALISING 52 | open import Semantics.NormalisationByEvaluation.βιξη 53 | 54 | normID'Bool : norm' (ε ⊢ `Bool `→ `Bool ∋ ID') ≡ `λ (`neu _ (`var zero)) 55 | normID'Bool = refl 56 | 57 | normID'Unit : norm' (ε ⊢ `Unit `→ `Unit ∋ ID') ≡ `λ `⟨⟩ 58 | normID'Unit = refl 59 | -------------------------------------------------------------------------------- /src/Syntax/MoggiML/Calculus.agda: -------------------------------------------------------------------------------- 1 | module Syntax.MoggiML.Calculus where 2 | 3 | open import Syntax.MoggiML.Type 4 | open import Syntax.Context Type 5 | open import Semantics.Environment.Core 6 | 7 | infix 5 _⊢_ 8 | data _⊢_ (Γ : Context) : Type → Set where 9 | 10 | `var : {σ : Type} → 11 | 12 | σ ∈ Γ → 13 | -------------- 14 | Γ ⊢ σ 15 | 16 | _`$_ : {σ τ : Type} → 17 | 18 | Γ ⊢ (σ `→# τ) → Γ ⊢ σ → 19 | -------------------------- 20 | Γ ⊢ # τ 21 | 22 | `λ : {σ τ : Type} → 23 | 24 | (Γ ∙ σ) ⊢ # τ → 25 | ---------------- 26 | Γ ⊢ (σ `→# τ) 27 | 28 | `⟨⟩ : 29 | ------------- 30 | Γ ⊢ `Unit 31 | 32 | `tt `ff : 33 | ------------- 34 | Γ ⊢ `Bool 35 | 36 | `ifte : {σ : Type} → 37 | 38 | Γ ⊢ `Bool → Γ ⊢ # σ → Γ ⊢ # σ → 39 | ------------------------------ 40 | Γ ⊢ # σ 41 | 42 | _`>>=_ : {σ τ : Type} → 43 | 44 | Γ ⊢ # σ → Γ ⊢ (σ `→# τ) → 45 | ------------------------------ 46 | Γ ⊢ # τ 47 | 48 | `return : {σ : Type} → 49 | 50 | Γ ⊢ σ → 51 | ------------- 52 | Γ ⊢ # σ 53 | 54 | wk^⊢ : Weakening Type _⊢_ 55 | wk^⊢ inc (`var v) = `var (lookup inc v) 56 | wk^⊢ inc (f `$ t) = wk^⊢ inc f `$ wk^⊢ inc t 57 | wk^⊢ inc (`λ t) = `λ (wk^⊢ (pop! inc) t) 58 | wk^⊢ inc `⟨⟩ = `⟨⟩ 59 | wk^⊢ inc `tt = `tt 60 | wk^⊢ inc `ff = `ff 61 | wk^⊢ inc (`ifte b l r) = `ifte (wk^⊢ inc b) (wk^⊢ inc l) (wk^⊢ inc r) 62 | wk^⊢ inc (m `>>= f) = wk^⊢ inc m `>>= wk^⊢ inc f 63 | wk^⊢ inc (`return a) = `return (wk^⊢ inc a) 64 | -------------------------------------------------------------------------------- /doc/models-cbn.agda: -------------------------------------------------------------------------------- 1 | module models-cbn where 2 | 3 | open import Level 4 | open import Data.Unit 5 | open import Function 6 | open import models 7 | 8 | module βιξη-cbn where 9 | 10 | 11 | open NormalForms βιξη.R public 12 | 13 | Kr : Model {Ty} zero 14 | Kr `1 = const ⊤ 15 | Kr `2 = Nf `2 16 | Kr (σ `→ τ) = □ (Kr σ) ⟶ Kr τ 17 | 18 | reify : ∀ σ → [ □ (Kr σ) ⟶ Nf σ ] 19 | reflect : ∀ σ → [ Ne σ ⟶ □ (Kr σ) ] 20 | 21 | reify `1 = const `⟨⟩ 22 | reify `2 = _$ refl 23 | reify (σ `→ τ) = λ {Γ} F → 24 | let var‿0 : ∀ {Δ} → Γ ∙ σ ⊆ Δ → □ (Kr σ) Δ 25 | var‿0 = λ inc ρ → reflect σ (`var (lookup (ρ [∘] inc) ze)) refl 26 | in `λ (reify τ (λ inc → F (inc [∘] step refl) (var‿0 inc))) 27 | 28 | reflect `1 = λ _ _ → tt 29 | reflect `2 = λ ne inc → `ne _ (th^ne _ inc ne) 30 | reflect (σ `→ τ) = λ ne inc v → 31 | let body = (th^ne _ inc ne `$ reify σ v) 32 | in reflect τ body refl 33 | 34 | Normalise : Semantics (□ ∘ Kr) (□ ∘ Kr) 35 | Normalise = record 36 | { th = λ _ → th^□ 37 | ; ⟦var⟧ = id 38 | ; ⟦λ⟧ = λ b inc v → b inc v refl 39 | ; _⟦$⟧_ = λ f t inc → f inc (th^□ inc t) 40 | ; ⟦⟨⟩⟧ = const tt 41 | ; ⟦tt⟧ = const `tt 42 | ; ⟦ff⟧ = const `ff 43 | ; ⟦if⟧ = λ {σ} → if σ 44 | } module If where 45 | 46 | if : ∀ σ → [ □ (Kr `2) ⟶ □ (Kr σ) ⟶ □ (Kr σ) ⟶ □ (Kr σ) ] 47 | if σ b l r inc with b inc 48 | ... | `ne _ t = reflect σ (`if t (grab l) (grab r)) refl where 49 | grab = th^nf σ inc ∘ reify σ 50 | ... | `tt = l inc 51 | ... | `ff = r inc 52 | 53 | norm : ∀ σ → [ Tm σ ⟶ Nf σ ] 54 | norm σ t = reify σ (Eval.sem Normalise dummy t) where 55 | 56 | dummy : ∀ {Γ} → (Γ -Env) (□ ∘ Kr) Γ 57 | dummy = pack (λ {σ} v → reflect σ (`var v)) 58 | -------------------------------------------------------------------------------- /src/Semantics/CPS/CBV.agda: -------------------------------------------------------------------------------- 1 | module Semantics.CPS.CBV where 2 | 3 | open import Syntax as λC 4 | open import Syntax.MoggiML as ML 5 | open import Semantics.Model 6 | open import Semantics.Environment as Env hiding (refl) 7 | open import Semantics.Specification 8 | open import Data.Unit 9 | open import Data.Product 10 | open import Function 11 | open import Relation.Binary.PropositionalEquality 12 | 13 | mutual 14 | 15 | ⟦_⟧ : λC.Type → ML.Type 16 | ⟦ `Unit ⟧ = `Unit 17 | ⟦ `Bool ⟧ = `Bool 18 | ⟦ σ `→ τ ⟧ = ⟦ σ ⟧ `→# ⟦ τ ⟧ 19 | 20 | #⟦_⟧ : λC.Type → ML.Type 21 | #⟦ σ ⟧ = # ⟦ σ ⟧ 22 | 23 | mutual 24 | 25 | ⟦⟧-inj : ∀ σ τ → ⟦ σ ⟧ ≡ ⟦ τ ⟧ → σ ≡ τ 26 | ⟦⟧-inj `Unit `Unit eq = refl 27 | ⟦⟧-inj `Bool `Bool eq = refl 28 | ⟦⟧-inj (σ₁ `→ τ₁) (σ₂ `→ τ₂) eq = 29 | let (eqσ , eqτ) = ML.`→-inj eq 30 | in cong₂ _`→_ (⟦⟧-inj σ₁ σ₂ eqσ) (⟦⟧-inj τ₁ τ₂ eqτ) 31 | ⟦⟧-inj `Unit `Bool () 32 | ⟦⟧-inj `Unit (_ `→ _) () 33 | ⟦⟧-inj `Bool `Unit () 34 | ⟦⟧-inj `Bool (_ `→ _) () 35 | ⟦⟧-inj (_ `→ _) `Unit () 36 | ⟦⟧-inj (_ `→ _) `Bool () 37 | 38 | #⟦⟧-inj : ∀ σ τ → #⟦ σ ⟧ ≡ #⟦ τ ⟧ → σ ≡ τ 39 | #⟦⟧-inj σ τ = ⟦⟧-inj σ τ ∘ #-inj 40 | 41 | Value : Model _ 42 | Value Γ σ = (⟦_⟧ λC.<$> Γ) ML.⊢ ⟦ σ ⟧ 43 | 44 | Computation : Model _ 45 | Computation Γ σ = (⟦_⟧ λC.<$> Γ) ML.⊢ #⟦ σ ⟧ 46 | 47 | CallByValue : Semantics Value Computation 48 | CallByValue = record 49 | { wk = ML.wk^⊢ ∘ Env.map ⟦_⟧ ⟦⟧-inj 50 | ; embed = pack (`var ∘ λC.map ⟦_⟧) 51 | ; ⟦var⟧ = `return 52 | ; ⟦λ⟧ = λ t → `return (`λ (t extend (`var zero))) 53 | ; _⟦$⟧_ = λ f t → f `>>= `λ (wk^⊢ extend t `>>= `λ (`var (1+ zero) `$ `var zero)) 54 | ; ⟦⟨⟩⟧ = `return `⟨⟩ 55 | ; ⟦tt⟧ = `return `tt 56 | ; ⟦ff⟧ = `return `ff 57 | ; ⟦ifte⟧ = λ b l r → b `>>= `λ (`ifte (`var zero) (wk^⊢ extend l) (wk^⊢ extend r)) 58 | } 59 | -------------------------------------------------------------------------------- /src/Semantics/Specification.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Specification where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment 6 | 7 | Kripke : {ℓ^E ℓ^M : Level} → Model ℓ^E → Model ℓ^M → 8 | Context → Type → Type → Set (ℓ^M ⊔ ℓ^E) 9 | Kripke 𝓔 𝓜 Γ σ τ = {Δ : Context} → Renaming Γ Δ → 𝓔 Δ σ → 𝓜 Δ τ 10 | 11 | record Semantics {ℓ^E ℓ^M : Level} 12 | (𝓔 : Model ℓ^E) (𝓜 : Model ℓ^M) : Set (ℓ^E ⊔ ℓ^M) where 13 | infixl 5 _⟦$⟧_ 14 | field 15 | 16 | wk : Weakening 𝓔 17 | embed : {Γ : Context} → Var Γ ⇒[ 𝓔 ] Γ 18 | ⟦var⟧ : {Γ : Context} {σ : Type} → 𝓔 Γ σ → 𝓜 Γ σ 19 | ⟦λ⟧ : {Γ : Context} {σ τ : Type} → Kripke 𝓔 𝓜 Γ σ τ → 𝓜 Γ (σ `→ τ) 20 | _⟦$⟧_ : Applicative 𝓜 21 | ⟦⟨⟩⟧ : {Γ : Context} → 𝓜 Γ `Unit 22 | ⟦tt⟧ : {Γ : Context} → 𝓜 Γ `Bool 23 | ⟦ff⟧ : {Γ : Context} → 𝓜 Γ `Bool 24 | ⟦ifte⟧ : {Γ : Context} {σ : Type} → 𝓜 Γ `Bool → 𝓜 Γ σ → 𝓜 Γ σ → 𝓜 Γ σ 25 | 26 | 27 | Evaluation : {ℓ^E ℓ^M : Level} (𝓔 : Model ℓ^E) (𝓜 : Model ℓ^M) → Set (ℓ^M ⊔ ℓ^E) 28 | Evaluation 𝓔 𝓜 = {Γ Δ : Context} {σ : Type} → Γ ⊢ σ → Var Γ ⇒[ 𝓔 ] Δ → 𝓜 Δ σ 29 | 30 | Evaluation' : {ℓ^M : Level} (𝓜 : Model ℓ^M) → Set ℓ^M 31 | Evaluation' 𝓜 = {Γ : Context} {σ : Type} → Γ ⊢ σ → 𝓜 Γ σ 32 | 33 | module Fundamental {ℓ^E ℓ^M : Level} 34 | {𝓔 : Model ℓ^E} {𝓜 : Model ℓ^M} (𝓢 : Semantics 𝓔 𝓜) where 35 | open Semantics 𝓢 36 | 37 | lemma : Evaluation 𝓔 𝓜 38 | lemma (`var v) ρ = ⟦var⟧ (lookup ρ v) 39 | lemma (t `$ u) ρ = lemma t ρ ⟦$⟧ lemma u ρ 40 | lemma (`λ t) ρ = ⟦λ⟧ (λ inc u → lemma t (wk[ wk ] inc ρ `∙ u)) 41 | lemma `⟨⟩ ρ = ⟦⟨⟩⟧ 42 | lemma `tt ρ = ⟦tt⟧ 43 | lemma `ff ρ = ⟦ff⟧ 44 | lemma (`ifte b l r) ρ = ⟦ifte⟧ (lemma b ρ) (lemma l ρ) (lemma r ρ) 45 | 46 | lemma' : Evaluation' 𝓜 47 | lemma' t = lemma t embed 48 | -------------------------------------------------------------------------------- /src/Semantics/NormalisationByEvaluation/βιξ.agda: -------------------------------------------------------------------------------- 1 | module Semantics.NormalisationByEvaluation.βιξ where 2 | 3 | open import Syntax.Core 4 | open import Syntax.Normal 5 | open import Syntax.Normal.Weakening 6 | open import Semantics.Model 7 | open import Semantics.Environment 8 | open import Semantics.Specification 9 | 10 | open import Data.Empty 11 | open import Data.Unit 12 | open import Data.Bool 13 | open import Data.Sum 14 | open import Function 15 | 16 | R : Type → Set 17 | R _ = ⊤ 18 | 19 | infix 5 _⊨_ _⊨⋆_ 20 | mutual 21 | 22 | _⊨_ : Model _ 23 | Γ ⊨ σ = Γ ⊢[ R ]^ne σ ⊎ Γ ⊨⋆ σ 24 | 25 | _⊨⋆_ : Model _ 26 | Γ ⊨⋆ `Unit = ⊤ 27 | Γ ⊨⋆ `Bool = Bool 28 | Γ ⊨⋆ (σ `→ τ) = {Δ : Context} → Renaming Γ Δ → Δ ⊨ σ → Δ ⊨ τ 29 | 30 | wk^⊨⋆ : Weakening _⊨⋆_ 31 | wk^⊨⋆ {σ = `Unit} ren T = T 32 | wk^⊨⋆ {σ = `Bool} ren T = T 33 | wk^⊨⋆ {σ = σ `→ τ} ren T = λ inc → T (trans ren inc) 34 | 35 | wk^⊨ : Weakening _⊨_ 36 | wk^⊨ ren (inj₁ ne) = inj₁ $ wk^ne ren ne 37 | wk^⊨ ren (inj₂ T) = inj₂ $ wk^⊨⋆ ren T 38 | 39 | reflect : Reflect R _⊨_ 40 | reflect σ = inj₁ 41 | 42 | mutual 43 | 44 | reify⋆ : Reify R _⊨⋆_ 45 | reify⋆ `Unit T = `⟨⟩ 46 | reify⋆ `Bool T = if T then `tt else `ff 47 | reify⋆ (σ `→ τ) T = `λ (reify τ (T extend var‿0)) 48 | where var‿0 = inj₁ $ `var zero 49 | 50 | reify : Reify R _⊨_ 51 | reify σ (inj₁ ne) = `neu _ ne 52 | reify σ (inj₂ T) = reify⋆ σ T 53 | 54 | infixr 5 _$$_ 55 | _$$_ : Applicative _⊨_ 56 | (inj₁ ne) $$ u = inj₁ $ ne `$ reify _ u 57 | (inj₂ F) $$ u = F refl u 58 | 59 | ifte : {Γ : Context} {σ : Type} → Γ ⊨ `Bool → Γ ⊨ σ → Γ ⊨ σ → Γ ⊨ σ 60 | ifte (inj₁ ne) l r = inj₁ $ `ifte ne (reify _ l) (reify _ r) 61 | ifte (inj₂ T) l r = if T then l else r 62 | 63 | Normalise : Semantics _⊨_ _⊨_ 64 | Normalise = record 65 | { embed = pack (reflect _ ∘ `var); wk = wk^⊨; ⟦var⟧ = id 66 | ; _⟦$⟧_ = _$$_; ⟦λ⟧ = inj₂ 67 | ; ⟦⟨⟩⟧ = inj₂ tt; ⟦tt⟧ = inj₂ true; ⟦ff⟧ = inj₂ false; ⟦ifte⟧ = ifte } 68 | 69 | eval : Evaluation _ _ 70 | eval = Fundamental.lemma Normalise 71 | 72 | eval' : Evaluation' _ 73 | eval' = Fundamental.lemma' Normalise 74 | 75 | norm : Normalisation R 76 | norm t = reify _ $ eval' t 77 | -------------------------------------------------------------------------------- /src/Semantics/NormalisationByEvaluation/βιξη.agda: -------------------------------------------------------------------------------- 1 | module Semantics.NormalisationByEvaluation.βιξη where 2 | 3 | open import Syntax.Core 4 | open import Syntax.Normal 5 | open import Syntax.Normal.Weakening 6 | open import Semantics.Model 7 | open import Semantics.Environment 8 | open import Semantics.Specification 9 | 10 | open import Data.Empty 11 | open import Data.Unit 12 | open import Function 13 | 14 | R : Type → Set 15 | R `Bool = ⊤ 16 | R _ = ⊥ 17 | 18 | infix 5 _⊨_ 19 | 20 | _⊨_ : Model _ 21 | Γ ⊨ `Unit = ⊤ 22 | Γ ⊨ `Bool = Γ ⊢[ R ]^nf `Bool 23 | Γ ⊨ (σ `→ τ) = {Δ : Context} → Renaming Γ Δ → Δ ⊨ σ → Δ ⊨ τ 24 | 25 | wk^⊨ : Weakening _⊨_ 26 | wk^⊨ {σ = `Unit} ren T = T 27 | wk^⊨ {σ = `Bool} ren T = wk^nf ren T 28 | wk^⊨ {σ = σ `→ τ} ren T = λ inc → T (trans ren inc) 29 | 30 | infixr 5 _$$_ 31 | _$$_ : Applicative _⊨_ 32 | t $$ u = t refl u 33 | 34 | mutual 35 | 36 | var‿0 : {Γ : Context} {σ : Type} → Γ ∙ σ ⊨ σ 37 | var‿0 = reflect _ (`var zero) 38 | 39 | reflect : Reflect R _⊨_ 40 | reflect `Unit t = tt 41 | reflect `Bool t = `neu _ t 42 | reflect (σ `→ τ) t = λ inc u → reflect τ (wk^ne inc t `$ reify σ u) 43 | 44 | reify : Reify R _⊨_ 45 | reify `Unit T = `⟨⟩ 46 | reify `Bool T = T 47 | reify (σ `→ τ) T = `λ (reify τ (T extend var‿0)) 48 | 49 | ifte : {Γ : Context} {σ : Type} → Γ ⊨ `Bool → Γ ⊨ σ → Γ ⊨ σ → Γ ⊨ σ 50 | ifte `tt l r = l 51 | ifte `ff l r = r 52 | ifte (`neu _ T) l r = reflect _ (`ifte T (reify _ l) (reify _ r)) 53 | 54 | Normalise : Semantics _⊨_ _⊨_ 55 | Semantics.wk Normalise = wk^⊨ 56 | Semantics.embed Normalise = pack (reflect _ ∘ `var) 57 | Semantics.⟦var⟧ Normalise = id 58 | Semantics.⟦λ⟧ Normalise = id 59 | Semantics._⟦$⟧_ Normalise = _$$_ 60 | Semantics.⟦⟨⟩⟧ Normalise = tt 61 | Semantics.⟦tt⟧ Normalise = `tt 62 | Semantics.⟦ff⟧ Normalise = `ff 63 | Semantics.⟦ifte⟧ Normalise = ifte 64 | 65 | eval : Evaluation _ _ 66 | eval = Fundamental.lemma Normalise 67 | 68 | eval' : Evaluation' _ 69 | eval' = Fundamental.lemma' Normalise 70 | 71 | norm : ∀ {Γ Δ σ} → Γ ⊢ σ → Var Γ ⇒[ _⊨_ ] Δ → Δ ⊢[ R ]^nf σ 72 | norm t ρ = reify _ $ eval t ρ 73 | 74 | norm' : Normalisation R 75 | norm' t = reify _ $ eval' t 76 | -------------------------------------------------------------------------------- /src/Syntax/Context/Core.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Context.Core where 2 | 3 | open import Data.Nat 4 | open import Data.Product hiding (map) 5 | open import Relation.Binary.PropositionalEquality 6 | 7 | -- A context is a backwards list 8 | infixl 10 _∙_ 9 | data Context (A : Set) : Set where 10 | ε : Context A 11 | _∙_ : Context A → A → Context A 12 | 13 | -- Contexts are functorial 14 | infixr 6 _<$>_ 15 | _<$>_ : {A B : Set} → (A → B) → Context A → Context B 16 | f <$> ε = ε 17 | f <$> xs ∙ x = (f <$> xs) ∙ f x 18 | 19 | -- A variable in that context is a de Bruijn index. 20 | -- Here we use a type family to ensure that the index 21 | -- is both well-scoped and well-typed. 22 | infix 5 _∈_ 23 | infixr 5 1+_ 24 | 25 | data _∈_ {A : Set} (σ : A) : Context A → Set where 26 | 27 | zero : {Γ : Context A} → 28 | 29 | --------------- 30 | σ ∈ (Γ ∙ σ) 31 | 32 | 1+_ : {Γ : Context A} {τ : A} → 33 | 34 | σ ∈ Γ → 35 | ------------------- 36 | σ ∈ (Γ ∙ τ) 37 | 38 | -- In order to have σ a PARAMETER of the inductive family, 39 | -- Agda forces us to use the type Type → Context → Set. 40 | -- However predicates of type Context → Type → Set are a 41 | -- central notion of our development as hinted at by the 42 | -- definition in Semantics.Model. 43 | -- So we provide a flipped version of _∈_ 44 | infix 5 _∋_ 45 | _∋_ : {A : Set} → Context A → A → Set 46 | Γ ∋ σ = σ ∈ Γ 47 | 48 | map : {A B : Set} {Γ : Context A} {σ : A} (f : A → B) → Γ ∋ σ → f <$> Γ ∋ f σ 49 | map f zero = zero 50 | map f (1+ v) = 1+ map f v 51 | 52 | map-inv : {A B : Set} {Γ : Context A} {τ : B} (f : A → B) → f <$> Γ ∋ τ → ∃ λ σ → τ ≡ f σ 53 | map-inv f = go _ refl where 54 | 55 | go : ∀ Γ {Δ τ} → f <$> Γ ≡ Δ → Δ ∋ τ → ∃ λ σ → τ ≡ f σ 56 | go ε () zero 57 | go ε () (1+ v) 58 | go (Γ ∙ _) refl zero = -, refl 59 | go (Γ ∙ _) refl (1+ v) = go Γ refl v 60 | 61 | map⁻¹ : {A B : Set} {Γ : Context A} {σ : A} (f : A → B) → 62 | (∀ σ τ → f σ ≡ f τ → σ ≡ τ) → f <$> Γ ∋ f σ → Γ ∋ σ 63 | map⁻¹ f inj = go _ refl refl where 64 | 65 | go : ∀ Γ {σ τ Δ} → f <$> Γ ≡ Δ → f σ ≡ τ → Δ ∋ τ → Γ ∋ σ 66 | go ε () eq zero 67 | go ε () eq (1+ v) 68 | go (Γ ∙ σ) refl eq zero rewrite inj _ _ eq = zero 69 | go (Γ ∙ σ) refl eq (1+ v) = 1+ go Γ refl eq v 70 | 71 | -- Each context has a size 72 | size : {A : Set} → Context A → ℕ 73 | size ε = zero 74 | size (Γ ∙ _) = 1 + size Γ 75 | 76 | -------------------------------------------------------------------------------- /src/Semantics/NormalisationByEvaluation/βι.agda: -------------------------------------------------------------------------------- 1 | module Semantics.NormalisationByEvaluation.βι where 2 | 3 | open import Syntax.Core 4 | open import Syntax.Normal 5 | open import Syntax.Normal.Weakening 6 | open import Semantics.Model 7 | open import Semantics.Environment 8 | open import Semantics.Specification 9 | open import Semantics.Syntactic.Instances 10 | 11 | open import Data.Empty 12 | open import Data.Unit 13 | open import Data.Bool 14 | open import Data.Sum 15 | open import Data.Product 16 | open import Function 17 | 18 | infix 5 _⊨_ _⊨⋆_ 19 | 20 | mutual 21 | 22 | _⊨_ : Model _ 23 | Γ ⊨ σ = Γ ⊢ σ × (Γ ⊢^whne σ ⊎ Γ ⊨⋆ σ) 24 | 25 | _⊨⋆_ : Model _ 26 | Γ ⊨⋆ `Unit = ⊤ 27 | Γ ⊨⋆ `Bool = Bool 28 | Γ ⊨⋆ (σ `→ τ) = {Δ : Context} → Renaming Γ Δ → Δ ⊨ σ → Δ ⊨ τ 29 | 30 | wk⋆ : Weakening _⊨⋆_ 31 | wk⋆ {σ = `Unit } ren T = T 32 | wk⋆ {σ = `Bool } ren T = T 33 | wk⋆ {σ = σ `→ τ} ren T = λ inc → T (trans ren inc) 34 | 35 | wk : Weakening _⊨_ 36 | wk inc (t , inj₁ ne) = rename inc t , inj₁ (wk^whne inc ne) 37 | wk inc (t , inj₂ T) = rename inc t , inj₂ (wk⋆ inc T) 38 | 39 | reflect : {Γ : Context} (σ : Type) → Γ ⊢^whne σ → Γ ⊨ σ 40 | reflect σ t = erase^whne t , inj₁ t 41 | 42 | mutual 43 | 44 | reify⋆ : {Γ : Context} (σ : Type) → Γ ⊨⋆ σ → Γ ⊢^whnf σ 45 | reify⋆ `Unit T = `⟨⟩ 46 | reify⋆ `Bool T = if T then `tt else `ff 47 | reify⋆ (σ `→ τ) T = `λ $ proj₁ $ T extend var‿0 48 | where var‿0 = reflect _ $ `var zero 49 | 50 | reify : {Γ : Context} (σ : Type) → Γ ⊨ σ → Γ ⊢^whnf σ 51 | reify σ (t , inj₁ ne) = `whne ne 52 | reify σ (_ , inj₂ T) = reify⋆ σ T 53 | 54 | infixr 5 _$$_ 55 | _$$_ : Applicative _⊨_ 56 | (t , inj₁ ne) $$ (u , U) = t `$ u , inj₁ (ne `$ u) 57 | (t , inj₂ T) $$ (u , U) = t `$ u , proj₂ (T refl (u , U)) 58 | 59 | ifte : {Γ : Context} {σ : Type} → Γ ⊨ `Bool → Γ ⊨ σ → Γ ⊨ σ → Γ ⊨ σ 60 | ifte (b , inj₁ ne) (l , L) (r , R) = `ifte b l r , inj₁ (`ifte ne l r) 61 | ifte (b , inj₂ B) (l , L) (r , R) = `ifte b l r , (if B then L else R) 62 | 63 | Normalise : Semantics _⊨_ _⊨_ 64 | Normalise = record 65 | { embed = pack (reflect _ ∘ `var); wk = wk; ⟦var⟧ = id 66 | ; _⟦$⟧_ = _$$_; ⟦λ⟧ = λ t → `λ (proj₁ $ t extend (reflect _ $ `var zero)) , inj₂ t 67 | ; ⟦⟨⟩⟧ = `⟨⟩ , inj₂ tt; ⟦tt⟧ = `tt , inj₂ true; ⟦ff⟧ = `ff , inj₂ false; ⟦ifte⟧ = ifte } 68 | 69 | eval : Evaluation _ _ 70 | eval = Fundamental.lemma Normalise 71 | 72 | eval' : Evaluation' _ 73 | eval' = Fundamental.lemma' Normalise 74 | 75 | norm : {Γ : Context} {σ : Type} → Γ ⊢ σ → Γ ⊢^whnf σ 76 | norm t = reify _ $ eval' t 77 | -------------------------------------------------------------------------------- /src/Properties/Relation/βιξη.agda: -------------------------------------------------------------------------------- 1 | module Properties.Relation.βιξη where 2 | 3 | open import Syntax.Core 4 | open import Syntax.Normal 5 | open import Syntax.Normal.Weakening 6 | open import Semantics.Environment as Env 7 | open import Semantics.NormalisationByEvaluation.βιξη 8 | open import Properties.Relation 9 | 10 | open import Data.Unit 11 | open import Function 12 | open import Relation.Binary.PropositionalEquality as PEq 13 | 14 | EQREL : (Γ : Context) (σ : Type) (T U : Γ ⊨ σ) → Set 15 | EQREL Γ `Unit T U = ⊤ 16 | EQREL Γ `Bool T U = T ≡ U 17 | EQREL Γ (σ `→ τ) T U = 18 | {Δ : Context} (inc : Renaming Γ Δ) {V W : Δ ⊨ σ} → 19 | EQREL Δ σ V W → EQREL Δ τ (T inc V) (U inc W) 20 | 21 | _≣_ : RModel _ _⊨_ _⊨_ 22 | _≣_ = mkRModel (λ {Γ} {σ} → EQREL Γ σ) 23 | 24 | sym≣ : Symmetric _≣_ 25 | sym≣ {σ = `Unit} eq = tt 26 | sym≣ {σ = `Bool} eq = sym eq 27 | sym≣ {σ = σ `→ τ} eq = λ inc eqVW → sym≣ (eq inc (sym≣ eqVW)) 28 | 29 | mutual 30 | 31 | trans≣ : Transitive _≣_ 32 | trans≣ {σ = `Unit} eq₁ eq₂ = tt 33 | trans≣ {σ = `Bool} eq₁ eq₂ = PEq.trans eq₁ eq₂ 34 | trans≣ {σ = σ `→ τ} eq₁ eq₂ = λ inc eqVW → trans≣ (eq₁ inc (refl≣ eqVW)) (eq₂ inc eqVW) 35 | 36 | refl≣ : {Γ : Context} {σ : Type} {S T : Γ ⊨ σ} → related _≣_ S T → related _≣_ S S 37 | refl≣ eq = trans≣ eq (sym≣ eq) 38 | 39 | wk^≣ : {Δ Γ : Context} {σ : Type} (ren : Renaming Γ Δ) {T U : Γ ⊨ σ} → 40 | related _≣_ T U → related _≣_ (wk^⊨ ren T) (wk^⊨ ren U) 41 | wk^≣ {σ = `Unit} ren eq = tt 42 | wk^≣ {σ = `Bool} ren eq = cong (wk^nf ren) eq 43 | wk^≣ {σ = σ `→ τ} ren eq = λ inc eqVW → eq (Env.trans ren inc) eqVW 44 | 45 | wk^⊨-trans : 46 | ∀ {σ Γ Δ Θ} inc₁ (inc₂ : Renaming Δ Θ) {T U : Γ ⊨ σ} → 47 | EQREL Γ σ T U → EQREL Θ σ (wk^⊨ inc₂ $ wk^⊨ inc₁ T) (wk^⊨ (Env.trans inc₁ inc₂) U) 48 | wk^⊨-trans {σ = `Unit} inc₁ inc₂ eq = tt 49 | wk^⊨-trans {σ = `Bool} inc₁ inc₂ eq rewrite eq = wk^nf-trans _ 50 | wk^⊨-trans {σ = σ `→ τ} inc₁ inc₂ eq = λ inc → eq _ 51 | 52 | mutual 53 | 54 | reify^≣ : {Γ : Context} (σ : Type) {T U : Γ ⊨ σ} → 55 | related _≣_ T U → reify σ T ≡ reify σ U 56 | reify^≣ `Unit R = PEq.refl 57 | reify^≣ `Bool R = R 58 | reify^≣ (σ `→ τ) R = cong `λ (reify^≣ τ (R (step Env.refl) (reflect^≣ σ PEq.refl))) 59 | 60 | reflect^≣ : {Γ : Context} (σ : Type) {t u : Γ ⊢[ R ]^ne σ} → 61 | t ≡ u → related _≣_ (reflect σ t) (reflect σ u) 62 | reflect^≣ `Unit eq = tt 63 | reflect^≣ `Bool eq = cong (`neu tt) eq 64 | reflect^≣ (σ `→ τ) eq = λ ren eq′ → 65 | reflect^≣ τ $ cong₂ (_`$_ ∘ wk^ne ren) eq $ reify^≣ σ eq′ 66 | -------------------------------------------------------------------------------- /src/Semantics/Environment/Core.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Environment.Core where 2 | 3 | open import Level as L hiding (zero) 4 | open import Syntax.Context as Context hiding (_<$>_ ; map) 5 | open import Semantics.Model.Core 6 | open import Data.Product hiding (map) 7 | open import Relation.Binary.PropositionalEquality as PEq hiding (refl) 8 | 9 | infix 5 Var_⇒[_]_ 10 | 11 | -- An environment Var Γ ⇒[ 𝓔 ] Δ simply maps each variable of 12 | -- type σ in Γ to an element of type 𝓔 Δ σ. 13 | 14 | record Var_⇒[_]_ {A : Set} {ℓ : Level} 15 | (Γ : Context A) (𝓔 : Model A ℓ) (Δ : Context A) : Set ℓ where 16 | constructor pack 17 | field lookup : {σ : A} (v : σ ∈ Γ) → 𝓔 Δ σ 18 | open Var_⇒[_]_ public 19 | 20 | infixr 10 _<$>_ 21 | _<$>_ : {A : Set} {ℓ ℓ′ : Level} {Γ Δ θ : Context A} {𝓓 : Model A ℓ} {𝓔 : Model A ℓ′} 22 | (f : {σ : A} → 𝓓 Δ σ → 𝓔 θ σ) → Var Γ ⇒[ 𝓓 ] Δ → Var Γ ⇒[ 𝓔 ] θ 23 | lookup (f <$> ρ) v = f (lookup ρ v) 24 | 25 | -- The simplest example of such an environment is Renaming. 26 | -- It comes with various combinators corresponding to the key 27 | -- elements identified by Altenkirch, Hofmann and Streicher 28 | -- in their 'category of weakenings' in "Categorical reconstruction 29 | -- of a reduction free normalization proof" 30 | 31 | Renaming : {A : Set} → Context A → Context A → Set 32 | Renaming Γ Δ = Var Γ ⇒[ _∋_ ] Δ 33 | 34 | map : {A B : Set} {Γ Δ : Context A} (f : A → B) → 35 | (∀ a b → f a ≡ f b → a ≡ b) → 36 | Renaming Γ Δ → Renaming (f Context.<$> Γ) (f Context.<$> Δ) 37 | lookup (map f inj inc) v = 38 | let (σ , eq) = map-inv f v 39 | v₁ = map⁻¹ f inj (subst (_ ∋_) eq v) 40 | v₂ = lookup inc v₁ 41 | v₃ = Context.map f v₂ 42 | in subst (_ ∋_) (sym eq) v₃ 43 | 44 | refl : {A : Set} {Γ : Context A} → Renaming Γ Γ 45 | lookup refl v = v 46 | 47 | step : {A : Set} {Γ Δ : Context A} {σ : A} → Renaming Γ Δ → Renaming Γ (Δ ∙ σ) 48 | step ren = 1+_ <$> ren 49 | 50 | extend : {A : Set} {Γ : Context A} {σ : A} → Renaming Γ (Γ ∙ σ) 51 | extend = step refl 52 | 53 | pop! : {A : Set} {Γ Δ : Context A} {σ : A} → Renaming Γ Δ → Renaming (Γ ∙ σ) (Δ ∙ σ) 54 | lookup (pop! ren) zero = zero 55 | lookup (pop! ren) (1+ v) = 1+ lookup ren v 56 | 57 | -- Renaming naturally gives rise to a notion of weakening for Models 58 | Weakening : (A : Set) {ℓ : Level} → Model A ℓ → Set ℓ 59 | Weakening A 𝓔 = {Γ Δ : Context A} {σ : A} → Renaming Γ Δ → 𝓔 Γ σ → 𝓔 Δ σ 60 | 61 | -- And Variables can trivially be renamed: 62 | wk^∋ : {A : Set} → Weakening A _∋_ 63 | wk^∋ ren v = lookup ren v 64 | -------------------------------------------------------------------------------- /src/Properties/Synchronisable/Instances.agda: -------------------------------------------------------------------------------- 1 | module Properties.Synchronisable.Instances where 2 | 3 | open import Syntax hiding (_<$>_) 4 | open import Syntax.Normal.Weakening 5 | open import Semantics.Environment as Env hiding (refl ; trans) 6 | open import Semantics.Specification using (module Semantics) 7 | open import Semantics.Instances 8 | open import Properties.Relation 9 | open import Properties.Relation.βιξη 10 | open import Properties.Synchronisable.Specification 11 | 12 | open import Data.Unit 13 | open import Data.Product 14 | open import Function 15 | open import Relation.Binary.PropositionalEquality 16 | 17 | SynchronisableRenamingSubstitution : 18 | Synchronisable 𝓢^Renaming 𝓢^Substitution (mkRModel (λ v t → `var v ≡ t)) Equality 19 | SynchronisableRenamingSubstitution = 20 | record 21 | { 𝓔^R‿wk = λ ren ρ^R → pack^R $ cong (rename ren) ∘ lookup^R ρ^R 22 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 23 | ; R⟦$⟧ = cong₂ _`$_ 24 | ; R⟦λ⟧ = λ r → cong `λ (r _ refl) 25 | ; R⟦⟨⟩⟧ = refl 26 | ; R⟦tt⟧ = refl 27 | ; R⟦ff⟧ = refl 28 | ; R⟦ifte⟧ = λ eqb eql → cong₂ (uncurry `ifte) (cong₂ _,_ eqb eql) 29 | } 30 | 31 | RenamingIsASubstitution : 32 | {Γ Δ : Context} {σ : Type} (t : Γ ⊢ σ) (ρ : Renaming Γ Δ) → 33 | rename ρ t ≡ substitute t (`var <$> ρ) 34 | RenamingIsASubstitution t ρ = corollary t (pack^R $ λ _ → refl) 35 | where corollary = Fundamental.lemma SynchronisableRenamingSubstitution 36 | 37 | ifteRelNorm : 38 | let open Semantics βιξη.Normalise in 39 | {Γ : Context} {σ : Type} {b^A b^B : Γ βιξη.⊨ `Bool} {l^A l^B r^A r^B : Γ βιξη.⊨ σ} → 40 | related _≣_ b^A b^B → related _≣_ l^A l^B → related _≣_ r^A r^B → 41 | related _≣_ (⟦ifte⟧ b^A l^A r^A) (⟦ifte⟧ b^B l^B r^B) 42 | ifteRelNorm {b^A = `tt} refl l^R r^R = l^R 43 | ifteRelNorm {b^A = `ff} refl l^R r^R = r^R 44 | ifteRelNorm {b^A = `neu _ ne} refl l^R r^R = 45 | reflect^≣ _ (cong₂ (`ifte ne) (reify^≣ _ l^R) (reify^≣ _ r^R)) 46 | 47 | SynchronisableNormalise : Synchronisable βιξη.Normalise βιξη.Normalise _≣_ _≣_ 48 | SynchronisableNormalise = 49 | record { 𝓔^R‿wk = λ ren ρ^R → pack^R $ wk^≣ ren ∘ lookup^R ρ^R 50 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 51 | ; R⟦$⟧ = λ f → f Env.refl 52 | ; R⟦λ⟧ = λ r → r 53 | ; R⟦⟨⟩⟧ = tt 54 | ; R⟦tt⟧ = refl 55 | ; R⟦ff⟧ = refl 56 | ; R⟦ifte⟧ = ifteRelNorm 57 | } 58 | 59 | refl^βιξη : {Γ Δ : Context} {σ : Type} (t : Γ ⊢ σ) 60 | {ρ^A ρ^B : Var Γ ⇒[ βιξη._⊨_ ] Δ} (ρ^R : `∀[ _≣_ ] ρ^A ρ^B) → 61 | related _≣_ (βιξη.eval t ρ^A) (βιξη.eval t ρ^B) 62 | refl^βιξη t ρ^R = lemma SynchronisableNormalise t ρ^R where 63 | open Properties.Synchronisable.Specification.Fundamental 64 | -------------------------------------------------------------------------------- /src/Syntax/Normal/Weakening.agda: -------------------------------------------------------------------------------- 1 | module Syntax.Normal.Weakening where 2 | 3 | open import Syntax.Type 4 | open import Syntax.Context 5 | open import Syntax.Normal 6 | open import Semantics.Environment as Env hiding (refl) 7 | open import Semantics.Syntactic.Instances 8 | open import Properties.Relation 9 | open import Data.Product 10 | open import Function 11 | open import Relation.Binary.PropositionalEquality 12 | 13 | mutual 14 | 15 | wk^ne : {R : Type → Set} → Weakening (_⊢[ R ]^ne_) 16 | wk^ne inc (`var v) = `var (wk^∋ inc v) 17 | wk^ne inc (ne `$ u) = wk^ne inc ne `$ wk^nf inc u 18 | wk^ne inc (`ifte ne l r) = `ifte (wk^ne inc ne) (wk^nf inc l) (wk^nf inc r) 19 | 20 | wk^nf : {R : Type → Set} → Weakening (_⊢[ R ]^nf_) 21 | wk^nf inc (`neu pr t) = `neu pr (wk^ne inc t) 22 | wk^nf inc `⟨⟩ = `⟨⟩ 23 | wk^nf inc `tt = `tt 24 | wk^nf inc `ff = `ff 25 | wk^nf inc (`λ nf) = `λ (wk^nf (pop! inc) nf) 26 | 27 | wk^whne : Weakening _⊢^whne_ 28 | wk^whne inc (`var v) = `var (wk^∋ inc v) 29 | wk^whne inc (ne `$ u) = wk^whne inc ne `$ rename inc u 30 | wk^whne inc (`ifte ne l r) = `ifte (wk^whne inc ne) (rename inc l) (rename inc r) 31 | 32 | wk^whnf : Weakening _⊢^whnf_ 33 | wk^whnf inc (`whne t) = `whne (wk^whne inc t) 34 | wk^whnf inc `⟨⟩ = `⟨⟩ 35 | wk^whnf inc `tt = `tt 36 | wk^whnf inc `ff = `ff 37 | wk^whnf inc (`λ b) = `λ (rename (pop! inc) b) 38 | 39 | mutual 40 | 41 | wk^nf-trans′ : 42 | ∀ {Γ Δ Θ σ R inc₁ inc₃} {inc₂ : Renaming Δ Θ} → 43 | `∀[ Equality ] (Env.trans inc₁ inc₂) inc₃ → 44 | (t : Γ ⊢[ R ]^nf σ) → wk^nf inc₂ (wk^nf inc₁ t) ≡ wk^nf inc₃ t 45 | wk^nf-trans′ eq (`neu pr t) = cong (`neu pr) $ wk^ne-trans′ eq t 46 | wk^nf-trans′ eq `⟨⟩ = refl 47 | wk^nf-trans′ eq `tt = refl 48 | wk^nf-trans′ eq `ff = refl 49 | wk^nf-trans′ eq (`λ t) = 50 | cong `λ $ wk^nf-trans′ ((cong 1+_ ∘ lookup^R eq) ∙^R′ refl) t 51 | 52 | wk^ne-trans′ : 53 | ∀ {Γ Δ Θ σ R inc₁ inc₃} {inc₂ : Renaming Δ Θ} → 54 | `∀[ Equality ] (Env.trans inc₁ inc₂) inc₃ → 55 | (t : Γ ⊢[ R ]^ne σ) → wk^ne inc₂ (wk^ne inc₁ t) ≡ wk^ne inc₃ t 56 | wk^ne-trans′ eq (`var v) = cong `var $ lookup^R eq v 57 | wk^ne-trans′ eq (t `$ u) = cong₂ _`$_ (wk^ne-trans′ eq t) (wk^nf-trans′ eq u) 58 | wk^ne-trans′ eq (`ifte t l r) = 59 | cong₂ (uncurry `ifte) (cong₂ _,_ (wk^ne-trans′ eq t) (wk^nf-trans′ eq l)) 60 | (wk^nf-trans′ eq r) 61 | 62 | wk^nf-trans : 63 | ∀ {Γ Δ Θ σ R inc₁} {inc₂ : Renaming Δ Θ} → 64 | (t : Γ ⊢[ R ]^nf σ) → wk^nf inc₂ (wk^nf inc₁ t) ≡ wk^nf (Env.trans inc₁ inc₂) t 65 | wk^nf-trans = wk^nf-trans′ $ pack^R $ λ _ → refl 66 | 67 | wk^ne-trans : 68 | ∀ {Γ Δ Θ σ R inc₁} {inc₂ : Renaming Δ Θ} → 69 | (t : Γ ⊢[ R ]^ne σ) → wk^ne inc₂ (wk^ne inc₁ t) ≡ wk^ne (Env.trans inc₁ inc₂) t 70 | wk^ne-trans = wk^ne-trans′ $ pack^R $ λ _ → refl 71 | -------------------------------------------------------------------------------- /doc/rules.sed: -------------------------------------------------------------------------------- 1 | # Super- and subscripts. 2 | ## fix to make it work with Agda 2.4.2.4 3 | s/\\textasciicircum\([^{]\)/\\textasciicircum\{\}\1/g 4 | ## Usual rules 5 | s/‿\([^\}]*\)\\textasciicircum{}\([^\}]*\)/\^\{\\AgdaFontStyle\{\\scriptscriptstyle \2\}\}\_\{\\AgdaFontStyle\{\\scriptscriptstyle \1\}\}/g 6 | s/\\textasciicircum{}\([^.\}]*\)‿\([^\}]*\)/\^\{\\AgdaFontStyle\{\\scriptscriptstyle \1\}\}\_\{\\AgdaFontStyle\{\\scriptscriptstyle \2\}\}/g 7 | s/\\textasciicircum{}\([^.\}]*\)/\{\^\\AgdaFontStyle\{\\scriptscriptstyle\{\}\1\}\}/g 8 | s/{\([^{.]*\)\({\^\\AgdaFontStyle{\\scriptscriptstyle{}[^\]*}\)/\{\{\1\}\2/g 9 | s/‿\([^\}]*\)/\_\\AgdaFontStyle\{\\scriptscriptstyle \1\}/g 10 | 11 | s/₀/\_\{\\scriptscriptstyle\{\}0\}/g 12 | s/\^//g 13 | # Operators 14 | s/>>=/\\mathbin\{>\\!\\!>\\mkern-6.7mu=\}/g 15 | s/>>/\\mathbin\{>\\!\\!>}/g 16 | s/++/+\\!+/g 17 | 18 | # Pointwise things 19 | s/⟶/\\,\\dot\{→\}\\,/g 20 | s/∙⊎/\\dot\{⊎\}/g 21 | s/∙×/\\dot\{×\}/g 22 | 23 | # Latex 24 | s/^\\begin{code}/\\begin\{code\}\n\\\\/g 25 | s/^\\end{code}/\\\\\\end\{code\}\n/g 26 | 27 | # Set levels 28 | s/L.zero//g 29 | s/\\AgdaSymbol{(}[^:]*\\AgdaSymbol{:} \\AgdaPostulate{Level}\\AgdaSymbol{)} \\AgdaSymbol{→} //g 30 | s/ \\AgdaBound{ℓ}//g 31 | s/\\AgdaPrimitive{L.suc}//g 32 | s/ \\AgdaPrimitive{⊔} //g 33 | s/ \?\\AgdaBound{{ℓ}{[^{]*{[^{]*{}[^}]*}}}//g 34 | s/\\AgdaSymbol{(}\\AgdaSymbol{)}//g 35 | s/ \\AgdaSymbol{(}\\AgdaSymbol{))}/\\AgdaSymbol\{)\}/g 36 | s/\\AgdaFunction{Model} \\AgdaSymbol{\\_}/\\AgdaFunction\{Model\}/g 37 | 38 | # Implicit arguments 39 | s/\\AgdaSymbol{λ} \\AgdaSymbol{\\{}\\AgdaBound{σ}\\AgdaSymbol{\\}} \\AgdaSymbol{\\{}\\AgdaBound{τ}\\AgdaSymbol{\\}} \\AgdaSymbol{→} //g 40 | s/\\AgdaSymbol{\\{}\\AgdaBound{σ}\\AgdaSymbol{\\}} \\AgdaSymbol{\\{}\\AgdaBound{τ}\\AgdaSymbol{\\};}/\\AgdaSymbol{;}/g 41 | s/\\AgdaSymbol{λ} \\AgdaSymbol{\\{}\\AgdaBound{σ}\\AgdaSymbol{\\}} \\AgdaSymbol{→} //g 42 | s/\\AgdaSymbol{\\{}\\AgdaBound{σ}\\AgdaSymbol{\\}} //g 43 | s/\\AgdaSymbol{\\{}.*\\AgdaSymbol{\\}}\([^=]*\)\\AgdaSymbol{=}/\1\\AgdaSymbol{=}/g 44 | s/\\AgdaSymbol{\\{}.*\\AgdaSymbol{\\}}[^()→;]*\\AgdaSymbol{→} //g 45 | s/\\AgdaSymbol{\\{}[^();]*\\AgdaSymbol{\\}}//g 46 | s/\\AgdaSymbol{\\{}[^;]*\\AgdaSymbol{\\}}//g 47 | 48 | # Hacks 49 | s/`→/`\\!\\!→/g 50 | s/`1/`\\!1/g 51 | s/`2/`\\!2/g 52 | s/𝓡/\\mathcal{R}/g 53 | 54 | # Awful, Awful Hacks 55 | s/\\AgdaSymbol{∀} \\AgdaBound{T}/\\AgdaSymbol{∀} \\AgdaSymbol{\\{}\\AgdaBound{Γ}\\AgdaSymbol{\\}} \\AgdaSymbol{→} \\AgdaBound{T}/ 56 | s/\\>\[13\]\\AgdaSymbol{(}\\AgdaBound{r} \\AgdaSymbol{:} \\<\[19\]%/\\>\[13\]\\AgdaSymbol{(}/ 57 | s/\\>\[19\]\\AgdaSymbol{∀} \\AgdaBound{inc}/\\AgdaSymbol{∀} \\AgdaBound{inc}/ 58 | s/\\AgdaFunction{CBN} \\AgdaSymbol{:}/\\AgdaFunction{CBX} \\AgdaSymbol{:}/ 59 | s/\\AgdaFunction{CBN} \\AgdaInductiveConstructor{`\\!1}/\\AgdaFunction{CBX} \\AgdaInductiveConstructor{`\\!1}/ 60 | s/\\AgdaFunction{CBN} \\AgdaInductiveConstructor{`\\!2}/\\AgdaFunction{CBX} \\AgdaInductiveConstructor{`\\!2}/ 61 | -------------------------------------------------------------------------------- /src/Properties/Fusable/Syntactic/Specification.agda: -------------------------------------------------------------------------------- 1 | module Properties.Fusable.Syntactic.Specification where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment hiding (refl) 6 | open import Semantics.Specification hiding (module Fundamental) 7 | open import Semantics.Syntactic.Specification hiding (module Fundamental) 8 | open import Properties.Relation 9 | open import Relation.Binary.PropositionalEquality 10 | 11 | record SyntacticFusable 12 | {ℓ^EA ℓ^EB ℓ^EC ℓ^REBC ℓ^RE : Level} 13 | {𝓔^A : Model ℓ^EA} {𝓔^B : Model ℓ^EB} {𝓔^C : Model ℓ^EC} 14 | (𝓢^A : Syntactic 𝓔^A) (𝓢^B : Syntactic 𝓔^B) (𝓢^C : Syntactic 𝓔^C) 15 | (𝓔^R‿BC : RModel ℓ^REBC 𝓔^B 𝓔^C) 16 | (𝓔^R : ∀ {Θ Δ Γ} → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set ℓ^RE) 17 | : Set (ℓ^RE ⊔ ℓ^REBC ⊔ ℓ^EC ⊔ ℓ^EB ⊔ ℓ^EA) 18 | where 19 | 20 | module 𝓢^A = Syntactic 𝓢^A 21 | module 𝓢^B = Syntactic 𝓢^B 22 | module 𝓢^C = Syntactic 𝓢^C 23 | 24 | 𝓡 : ∀ {Γ Δ Θ σ} → Γ ⊢ σ → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set _ 25 | 𝓡 t ρ^A ρ^B ρ^C = 26 | let open Semantics.Syntactic.Specification.Fundamental 27 | in lemma 𝓢^B (lemma 𝓢^A t ρ^A) ρ^B ≡ lemma 𝓢^C t ρ^C 28 | 29 | field 30 | 31 | 𝓔^R‿∙ : ∀ {Γ Δ Θ σ} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} → ∀ {ρ^B ρ^C u^B} {u^C : 𝓔^C Θ σ} → 32 | 𝓔^R ρ^A ρ^B ρ^C → related 𝓔^R‿BC u^B u^C → 33 | 𝓔^R (wk[ 𝓢^A.wk ] extend ρ^A `∙ lookup 𝓢^A.embed zero) 34 | (ρ^B `∙ u^B) (ρ^C `∙ u^C) 35 | 36 | 𝓔^R‿wk : ∀ {Γ Δ Θ E} (inc : Renaming Θ E) → {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} → ∀ {ρ^B ρ^C} → 37 | 𝓔^R ρ^A ρ^B ρ^C → 𝓔^R ρ^A (wk[ 𝓢^B.wk ] inc ρ^B) (wk[ 𝓢^C.wk ] inc ρ^C) 38 | 39 | R⟦var⟧ : ∀ {Γ Δ Θ σ} (v : σ ∈ Γ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 40 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 (`var v) ρ^A ρ^B ρ^C 41 | 42 | embed^BC : ∀ {Γ σ} → related 𝓔^R‿BC {Γ ∙ σ} (lookup 𝓢^B.embed zero) (lookup 𝓢^C.embed zero) 43 | 44 | 45 | module Fundamental 46 | {ℓ^EA ℓ^EB ℓ^EC ℓ^REBC ℓ^RE : Level} 47 | {𝓔^A : Model ℓ^EA} {𝓔^B : Model ℓ^EB} {𝓔^C : Model ℓ^EC} 48 | {𝓢^A : Syntactic 𝓔^A} {𝓢^B : Syntactic 𝓔^B} {𝓢^C : Syntactic 𝓔^C} 49 | {𝓔^R‿BC : RModel ℓ^REBC 𝓔^B 𝓔^C} 50 | {𝓔^R : ∀ {Θ Δ Γ} → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set ℓ^RE} 51 | (𝓕 : SyntacticFusable 𝓢^A 𝓢^B 𝓢^C 𝓔^R‿BC 𝓔^R) 52 | where 53 | 54 | open SyntacticFusable 𝓕 55 | open import Properties.Fusable.Specification 56 | open import Data.Product 57 | 58 | 𝓜^A = Semantics.Syntactic.Specification.Fundamental.syntactic 𝓢^A 59 | 𝓜^B = Semantics.Syntactic.Specification.Fundamental.syntactic 𝓢^B 60 | 𝓜^C = Semantics.Syntactic.Specification.Fundamental.syntactic 𝓢^C 61 | 62 | syntactic : Fusable 𝓜^A 𝓜^B 𝓜^C 𝓔^R‿BC 𝓔^R (mkRModel _≡_) 63 | syntactic = record 64 | { reify^A = λ t → t 65 | ; 𝓔^R‿∙ = 𝓔^R‿∙ 66 | ; 𝓔^R‿wk = 𝓔^R‿wk 67 | ; R⟦var⟧ = R⟦var⟧ 68 | ; R⟦$⟧ = λ f t ρ^R → cong₂ _`$_ 69 | ; R⟦λ⟧ = λ t ρ^R r → cong `λ (r extend embed^BC) 70 | ; R⟦⟨⟩⟧ = λ ρ^R → refl 71 | ; R⟦tt⟧ = λ ρ^R → refl 72 | ; R⟦ff⟧ = λ ρ^R → refl 73 | ; R⟦ifte⟧ = λ b l r ρ^R eqb eql → cong₂ (uncurry `ifte) (cong₂ _,_ eqb eql) 74 | } 75 | 76 | lemma : ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 77 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 t ρ^A ρ^B ρ^C 78 | lemma = Fundamental.lemma syntactic 79 | -------------------------------------------------------------------------------- /src/Semantics/Printing.agda: -------------------------------------------------------------------------------- 1 | module Semantics.Printing where 2 | 3 | open import Syntax.Core hiding (_<$>_) 4 | open import Semantics.Environment hiding (_<$>_) 5 | open import Semantics.Specification 6 | 7 | open import Function 8 | open import Data.Nat 9 | open import Data.Product hiding (map) 10 | open import Data.Char using (Char) 11 | open import Data.String hiding (show) 12 | open import Data.Nat.Show as NatShow 13 | open import Data.List as List using (List; _∷_; []) 14 | open import Data.List.NonEmpty as List⁺ using (List⁺; _∷_) 15 | 16 | open import Codata.Thunk 17 | open import Codata.Stream as Stream using (Stream ; head ; tail ; zipWith ; _∷_) 18 | open import Category.Monad.State 19 | open RawIMonadState (StateMonadState (Stream String _)) hiding (zipWith ; pure) 20 | 21 | M : Set → Set 22 | M = State (Stream String _) 23 | 24 | record Name (Γ : Context) (σ : Type) : Set where 25 | constructor mkName 26 | field runName : String 27 | 28 | record Printer (Γ : Context) (σ : Type) : Set where 29 | constructor mkPrinter 30 | field runPrinter : M String 31 | 32 | open Name public 33 | open Printer public 34 | 35 | formatλ : String → String → String 36 | formatλ x b = "λ" ++ x ++ ". " ++ b 37 | 38 | format$ : String → String → String 39 | format$ f t = f ++ " (" ++ t ++ ")" 40 | 41 | formatIf : String → String → String → String 42 | formatIf b l r = "if (" ++ b ++ ") then (" ++ l ++ ") else (" ++ r ++ ")" 43 | 44 | embed : {Γ : Context} → Var Γ ⇒[ Name ] Γ 45 | lookup embed v = mkName (show (deBruijn v)) where 46 | 47 | deBruijn : {Γ : Context} {σ : Type} → σ ∈ Γ → ℕ 48 | deBruijn zero = 0 49 | deBruijn (1+ n) = 1 + deBruijn n 50 | 51 | Printing : Semantics Name Printer 52 | Printing = record 53 | { embed = embed 54 | ; wk = λ _ → mkName ∘ runName 55 | ; ⟦var⟧ = mkPrinter ∘ return ∘ runName 56 | ; _⟦$⟧_ = λ mf mt → mkPrinter $ format$ <$> runPrinter mf ⊛ runPrinter mt 57 | ; ⟦λ⟧ = λ {_} {σ} mb → 58 | mkPrinter $ get >>= λ names → let `x` = head names in 59 | put (tail names) >>= λ _ → 60 | runPrinter (mb (step {σ = σ} refl) (mkName `x`)) >>= λ `b` → 61 | return $ formatλ `x` `b` 62 | ; ⟦⟨⟩⟧ = mkPrinter $ return "⟨⟩" 63 | ; ⟦tt⟧ = mkPrinter $ return "tt" 64 | ; ⟦ff⟧ = mkPrinter $ return "ff" 65 | ; ⟦ifte⟧ = λ mb ml mr → mkPrinter $ 66 | formatIf <$> runPrinter mb ⊛ runPrinter ml ⊛ runPrinter mr } 67 | 68 | 69 | alphabetWithSuffix : String → List⁺ String 70 | alphabetWithSuffix suffix = List⁺.map (λ c → fromList (c ∷ []) ++ suffix) 71 | $′ 'a' ∷ toList "bcdefghijklmnopqrstuvwxyz" 72 | 73 | allNats : Stream ℕ _ 74 | allNats = Stream.unfold < id , suc > 0 75 | 76 | names : Stream String _ 77 | names = Stream.concat 78 | $′ Stream.map alphabetWithSuffix 79 | $′ "" ∷ λ where .force → Stream.map NatShow.show allNats 80 | 81 | name : {Γ : Context} {σ : Type} → M (Name Γ σ) 82 | name = do 83 | names ← get 84 | put (tail names) 85 | return (mkName $ head names) 86 | 87 | init : (Γ Δ : Context) → M (Var Γ ⇒[ Name ] Δ) 88 | init ε Δ = return `ε 89 | init (Γ ∙ σ) Δ = (_`∙_ <$> init Γ Δ) ⊛ name 90 | 91 | init' : {Γ : Context} → M (Var Γ ⇒[ Name ] Γ) 92 | init' = init _ _ 93 | 94 | printer : Evaluation Name Printer 95 | printer = Fundamental.lemma Printing 96 | 97 | printer' : Evaluation' Printer 98 | printer' = Fundamental.lemma' Printing 99 | 100 | print : {Γ : Context} {σ : Type} → Γ ⊢ σ → String 101 | print t = 102 | let printer = Fundamental.lemma Printing t 103 | in proj₁ $ init' >>= runPrinter ∘ printer $ names 104 | -------------------------------------------------------------------------------- /src/Properties/Synchronisable/Specification.agda: -------------------------------------------------------------------------------- 1 | module Properties.Synchronisable.Specification where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment 6 | open import Semantics.Specification hiding (module Fundamental) 7 | open import Properties.Relation 8 | 9 | record Synchronisable 10 | {ℓ^EA ℓ^MA ℓ^EB ℓ^MB ℓ^RE ℓ^RM : Level} 11 | {𝓔^A : Model ℓ^EA} {𝓜^A : Model ℓ^MA} 12 | {𝓔^B : Model ℓ^EB} {𝓜^B : Model ℓ^MB} 13 | (𝓢^A : Semantics 𝓔^A 𝓜^A) (𝓢^B : Semantics 𝓔^B 𝓜^B) 14 | (𝓔^R : RModel ℓ^RE 𝓔^A 𝓔^B) (𝓜^R : RModel ℓ^RM 𝓜^A 𝓜^B) 15 | : Set (ℓ^RE ⊔ ℓ^RM ⊔ ℓ^EA ⊔ ℓ^EB ⊔ ℓ^MA ⊔ ℓ^MB) where 16 | 17 | module 𝓢^A = Semantics 𝓢^A 18 | module 𝓢^B = Semantics 𝓢^B 19 | 𝓡 = related 𝓜^R 20 | 21 | field 22 | 23 | 𝓔^R‿wk : {Γ Δ Θ : Context} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Γ ⇒[ 𝓔^B ] Δ} → 24 | 25 | (ren : Renaming Δ Θ) → `∀[ 𝓔^R ] ρ^A ρ^B → 26 | ---------------------------------------------------------- 27 | `∀[ 𝓔^R ] (wk[ 𝓢^A.wk ] ren ρ^A) (wk[ 𝓢^B.wk ] ren ρ^B) 28 | 29 | R⟦var⟧ : {Γ Δ : Context} {σ : Type} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Γ ⇒[ 𝓔^B ] Δ} 30 | 31 | (v : σ ∈ Γ) (ρ^R : `∀[ 𝓔^R ] ρ^A ρ^B) → 32 | -------------------------------------------------------------- 33 | 𝓡 (𝓢^A.⟦var⟧ (lookup ρ^A v)) (𝓢^B.⟦var⟧ (lookup ρ^B v)) 34 | 35 | R⟦λ⟧ : {Γ : Context} {σ τ : Type} 36 | {f^A : Kripke 𝓔^A 𝓜^A Γ σ τ} {f^B : Kripke 𝓔^B 𝓜^B Γ σ τ} → 37 | 38 | RKripke 𝓔^R 𝓜^R f^A f^B → 39 | ----------------------------------------------------------------------- 40 | 𝓡 (𝓢^A.⟦λ⟧ f^A) (𝓢^B.⟦λ⟧ f^B) 41 | 42 | R⟦$⟧ : RApplicative 𝓢^A._⟦$⟧_ 𝓢^B._⟦$⟧_ 𝓜^R 43 | 44 | R⟦⟨⟩⟧ : {Γ : Context} → 45 | 46 | ------------------------------ 47 | 𝓡 {Γ} 𝓢^A.⟦⟨⟩⟧ 𝓢^B.⟦⟨⟩⟧ 48 | 49 | R⟦tt⟧ : {Γ : Context} → 50 | 51 | ------------------------------ 52 | 𝓡 {Γ} 𝓢^A.⟦tt⟧ 𝓢^B.⟦tt⟧ 53 | 54 | R⟦ff⟧ : {Γ : Context} → 55 | 56 | ------------------------------ 57 | 𝓡 {Γ} 𝓢^A.⟦ff⟧ 𝓢^B.⟦ff⟧ 58 | 59 | R⟦ifte⟧ : {Γ : Context} {σ : Type} 60 | {b^A : 𝓜^A Γ `Bool} {b^B : 𝓜^B Γ `Bool} 61 | {l^A r^A : 𝓜^A Γ σ} {l^B r^B : 𝓜^B Γ σ} → 62 | 63 | 𝓡 b^A b^B → related 𝓜^R l^A l^B → related 𝓜^R r^A r^B → 64 | ---------------------------------------------------------- 65 | 𝓡 (𝓢^A.⟦ifte⟧ b^A l^A r^A) (𝓢^B.⟦ifte⟧ b^B l^B r^B) 66 | 67 | 68 | module Fundamental 69 | {ℓ^EA ℓ^MA ℓ^EB ℓ^MB ℓ^RE ℓ^RM : Level} 70 | {𝓔^A : Model ℓ^EA} {𝓜^A : Model ℓ^MA} 71 | {𝓔^B : Model ℓ^EB} {𝓜^B : Model ℓ^MB} 72 | {𝓢^A : Semantics 𝓔^A 𝓜^A} {𝓢^B : Semantics 𝓔^B 𝓜^B} 73 | {𝓔^R : RModel ℓ^RE 𝓔^A 𝓔^B} {𝓜^R : RModel ℓ^RM 𝓜^A 𝓜^B} 74 | (𝓢^R : Synchronisable 𝓢^A 𝓢^B 𝓔^R 𝓜^R) 75 | where 76 | 77 | open Synchronisable 𝓢^R 78 | eval = Semantics.Specification.Fundamental.lemma 79 | 80 | lemma : {Γ Δ : Context} {σ : Type} (t : Γ ⊢ σ) 81 | {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Γ ⇒[ 𝓔^B ] Δ} (ρ^R : `∀[ 𝓔^R ] ρ^A ρ^B) → 82 | 𝓡 (eval 𝓢^A t ρ^A) (eval 𝓢^B t ρ^B) 83 | lemma (`var v) ρ^R = R⟦var⟧ v ρ^R 84 | lemma (f `$ t) ρ^R = R⟦$⟧ (lemma f ρ^R) (lemma t ρ^R) 85 | lemma (`λ t) ρ^R = R⟦λ⟧ (λ inc u^R → lemma t (𝓔^R‿wk inc ρ^R ∙^R u^R)) 86 | lemma `⟨⟩ ρ^R = R⟦⟨⟩⟧ 87 | lemma `tt ρ^R = R⟦tt⟧ 88 | lemma `ff ρ^R = R⟦ff⟧ 89 | lemma (`ifte b l r) ρ^R = R⟦ifte⟧ (lemma b ρ^R) (lemma l ρ^R) (lemma r ρ^R) 90 | 91 | -------------------------------------------------------------------------------- /src/Properties/Relation.agda: -------------------------------------------------------------------------------- 1 | module Properties.Relation where 2 | 3 | open import Level hiding (zero) 4 | open import Syntax.Type 5 | open import Syntax.Context Type hiding (_∋_) 6 | open import Semantics.Model 7 | open import Semantics.Environment 8 | open import Semantics.Specification 9 | open import Function 10 | open import Relation.Binary.PropositionalEquality as PropEq 11 | 12 | record RModel 13 | {ℓ^A ℓ^B : Level} (ℓ^R : Level) 14 | (𝓜^A : Model ℓ^A) (𝓜^B : Model ℓ^B) 15 | : Set (suc ℓ^R ⊔ ℓ^B ⊔ ℓ^A) where 16 | constructor mkRModel 17 | field related : {Γ : Context} {σ : Type} → 𝓜^A Γ σ → 𝓜^B Γ σ → Set ℓ^R 18 | open RModel public 19 | 20 | Equality : {ℓ : Level} {𝓜 : Model ℓ} → RModel _ 𝓜 𝓜 21 | Equality = mkRModel _≡_ 22 | 23 | Symmetric : {ℓ^A ℓ^R : Level} {𝓜^A : Model ℓ^A} → RModel ℓ^R 𝓜^A 𝓜^A → Set (ℓ^R ⊔ ℓ^A) 24 | Symmetric {𝓜^A = 𝓜^A} 𝓜^R = {Γ : Context} {σ : Type} {T U : 𝓜^A Γ σ} → 25 | related 𝓜^R T U → related 𝓜^R U T 26 | 27 | Transitive : {ℓ^A ℓ^R : Level} {𝓜^A : Model ℓ^A} → RModel ℓ^R 𝓜^A 𝓜^A → Set (ℓ^R ⊔ ℓ^A) 28 | Transitive {𝓜^A = 𝓜^A} 𝓜^R = {Γ : Context} {σ : Type} {S T U : 𝓜^A Γ σ} → 29 | related 𝓜^R S T → related 𝓜^R T U → related 𝓜^R S U 30 | 31 | RKripke : 32 | {ℓ^EA ℓ^EB ℓ^MA ℓ^MB : Level} {ℓ^ER ℓ^MR : Level} 33 | {𝓔^A : Model ℓ^EA} {𝓔^B : Model ℓ^EB} (𝓔^R : RModel ℓ^ER 𝓔^A 𝓔^B) → 34 | {𝓜^A : Model ℓ^MA} {𝓜^B : Model ℓ^MB} (𝓜^R : RModel ℓ^MR 𝓜^A 𝓜^B) → 35 | {Γ : Context} {σ τ : Type} → Kripke 𝓔^A 𝓜^A Γ σ τ → Kripke 𝓔^B 𝓜^B Γ σ τ → 36 | Set (ℓ^MR ⊔ (ℓ^ER ⊔ (ℓ^EB ⊔ ℓ^EA))) 37 | RKripke {𝓔^A = 𝓔^A} {𝓔^B} 𝓔^R 𝓜^R {Γ} {σ} {τ} f^A f^B = 38 | {Δ : Context} (ren : Renaming Γ Δ) {u^A : 𝓔^A Δ σ} {u^B : 𝓔^B Δ σ} 39 | (u^R : related 𝓔^R u^A u^B) → related 𝓜^R (f^A ren u^A) (f^B ren u^B) 40 | 41 | RApplicative : {ℓ^A ℓ^B ℓ^R : Level} {𝓜^A : Model ℓ^A} {𝓜^B : Model ℓ^B} → 42 | Applicative 𝓜^A → Applicative 𝓜^B → RModel ℓ^R 𝓜^A 𝓜^B → 43 | Set (ℓ^R ⊔ (ℓ^B ⊔ ℓ^A)) 44 | RApplicative {𝓜^A = 𝓜^A} {𝓜^B} _$$^A_ _$$^B_ 𝓜^R = 45 | {Γ : Context} {σ τ : Type} 46 | {f^A : 𝓜^A Γ (σ `→ τ)} {f^B : 𝓜^B Γ (σ `→ τ)} 47 | {t^A : 𝓜^A Γ σ} {t^B : 𝓜^B Γ σ} → 48 | 49 | related 𝓜^R f^A f^B → related 𝓜^R t^A t^B → 50 | ----------------------------------------------- 51 | related 𝓜^R (f^A $$^A t^A) (f^B $$^B t^B) 52 | 53 | 54 | record `∀[_] {ℓ^A ℓ^B ℓ^R : Level} 55 | {𝓔^A : Model ℓ^A} {𝓔^B : Model ℓ^B} (𝓔^R : RModel ℓ^R 𝓔^A 𝓔^B) 56 | {Γ Δ : Context} (ρ^A : Var Γ ⇒[ 𝓔^A ] Δ) (ρ^B : Var Γ ⇒[ 𝓔^B ] Δ) : Set ℓ^R where 57 | constructor pack^R 58 | field lookup^R : {σ : Type} (v : σ ∈ Γ) → related 𝓔^R (lookup ρ^A v) (lookup ρ^B v) 59 | open `∀[_] public 60 | 61 | ε^R : {ℓ^A ℓ^B ℓ^R : Level} {𝓔^A : Model ℓ^A} {𝓔^B : Model ℓ^B} {𝓔^R : RModel ℓ^R 𝓔^A 𝓔^B} → 62 | {Γ : Context} → `∀[ 𝓔^R ] (Var ε ⇒[ 𝓔^A ] Γ ∋ `ε) `ε 63 | lookup^R ε^R () 64 | 65 | _∙^R_ : 66 | {ℓ^A ℓ^B ℓ^R : Level} {𝓔^A : Model ℓ^A} {𝓔^B : Model ℓ^B} {𝓔^R : RModel ℓ^R 𝓔^A 𝓔^B} → 67 | {Δ Γ : Context} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Γ ⇒[ 𝓔^B ] Δ} (ρ^R : `∀[ 𝓔^R ] ρ^A ρ^B) 68 | {σ : Type} {u^A : 𝓔^A Δ σ} {u^B : 𝓔^B Δ σ} → related 𝓔^R u^A u^B → 69 | `∀[ 𝓔^R ] (ρ^A `∙ u^A) (ρ^B `∙ u^B) 70 | lookup^R (ρ^R ∙^R u^R) zero = u^R 71 | lookup^R (ρ^R ∙^R u^R) (1+ v) = lookup^R ρ^R v 72 | 73 | _∙^R′_ : 74 | {ℓ^A ℓ^B ℓ^R : Level} {𝓔^A : Model ℓ^A} {𝓔^B : Model ℓ^B} {𝓔^R : RModel ℓ^R 𝓔^A 𝓔^B} → 75 | {Δ Γ : Context} {σ : Type} {ρ^A : Var (Γ ∙ σ) ⇒[ 𝓔^A ] Δ} {ρ^B : Var Γ ∙ σ ⇒[ 𝓔^B ] Δ} 76 | (ρ^R : ∀ {σ} (v : σ ∈ Γ) → related 𝓔^R (lookup ρ^A (1+ v)) (lookup ρ^B (1+ v))) → 77 | related 𝓔^R (lookup ρ^A zero) (lookup ρ^B zero) → 78 | `∀[ 𝓔^R ] ρ^A ρ^B 79 | lookup^R (ρ^R ∙^R′ u^R) zero = u^R 80 | lookup^R (ρ^R ∙^R′ u^R) (1+ v) = ρ^R v 81 | 82 | refl^R : {ℓ : Level} {𝓔 : Model ℓ} {Γ Δ : Context} {ρ : Var Γ ⇒[ 𝓔 ] Δ} → `∀[ Equality ] ρ ρ 83 | refl^R = pack^R (λ _ → PropEq.refl) 84 | -------------------------------------------------------------------------------- /doc/motivation.lagda: -------------------------------------------------------------------------------- 1 | \begin{code} 2 | module motivation where 3 | 4 | open import Data.List hiding ([_]) 5 | open import Function 6 | 7 | data Type : Set where 8 | base : Type 9 | arr : Type → Type → Type 10 | 11 | Cx' = List Type 12 | Model' = Type → Cx' → Set 13 | 14 | infixr 8 _⇒_ 15 | _⇒_ : (Cx' → Set) → (Cx' → Set) → Cx' → Set 16 | (f ⇒ g) Γ = f Γ → g Γ 17 | 18 | [_]' : (Cx' → Set) → Set 19 | [ P ]' = ∀ {x} → P x 20 | 21 | infix 9 _⊢_ 22 | _⊢_ : Type → (Cx' → Set) → Cx' → Set 23 | (σ ⊢ T) Γ = T (σ ∷ Γ) 24 | 25 | 26 | data Var : Model' where 27 | ze : ∀ {σ} → [ σ ⊢ Var σ ]' 28 | su : ∀ {σ τ} → [ Var σ ⇒ τ ⊢ Var σ ]' 29 | 30 | □ : (Cx' → Set) → (Cx' → Set) 31 | □ P Γ = ∀ {Δ} → (∀ {σ} → Var σ Γ → Var σ Δ) → P Δ 32 | 33 | 34 | data Tm : Model' where 35 | `var : ∀ {σ} → [ Var σ ⇒ Tm σ ]' 36 | _`$_ : ∀ {σ τ} → [ Tm (arr σ τ) ⇒ Tm σ ⇒ Tm τ ]' 37 | `λ : ∀ {σ τ} → [ σ ⊢ Tm τ ⇒ Tm (arr σ τ) ]' 38 | \end{code} 39 | %<*ren> 40 | \begin{code} 41 | ren : {Γ Δ : List Type} → (∀ {σ} → Var σ Γ → Var σ Δ) → (∀ {σ} → Tm σ Γ → Tm σ Δ) 42 | ren ρ (`var v) = `var (ρ v) 43 | ren ρ (f `$ t) = ren ρ f `$ ren ρ t 44 | ren ρ (`λ b) = `λ (ren ((su ∘ ρ) -, ze) b) 45 | \end{code} 46 | % 47 | \begin{code} 48 | where 49 | 50 | _-,_ : ∀ {Γ σ Δ} → (∀ {τ} → Var τ Γ → Var τ Δ) → Var σ Δ → ∀ {τ} → Var τ (σ ∷ Γ) → Var τ Δ 51 | (ρ -, v) ze = v 52 | (ρ -, v) (su k) = ρ k 53 | \end{code} 54 | %<*sub> 55 | \begin{code} 56 | sub : {Γ Δ : List Type} → (∀ {σ} → Var σ Γ → Tm σ Δ) → (∀ {σ} → Tm σ Γ → Tm σ Δ) 57 | sub ρ (`var v) = ρ v 58 | sub ρ (f `$ t) = sub ρ f `$ sub ρ t 59 | sub ρ (`λ b) = `λ (sub ((ren su ∘ ρ) -, `var ze) b) 60 | \end{code} 61 | % 62 | \begin{code} 63 | where 64 | 65 | _-,_ : ∀ {Γ σ Δ} → (∀ {τ} → Var τ Γ → Tm τ Δ) → Tm σ Δ → ∀ {τ} → Var τ (σ ∷ Γ) → Tm τ Δ 66 | (ρ -, v) ze = v 67 | (ρ -, v) (su k) = ρ k 68 | 69 | record Kit (◆ : Model') : Set where 70 | field 71 | var : ∀ {σ} → [ ◆ σ ⇒ Tm σ ]' 72 | zro : ∀ {σ} → [ σ ⊢ ◆ σ ]' 73 | wkn : ∀ {σ τ} → [ ◆ τ ⇒ σ ⊢ ◆ τ ]' 74 | 75 | module kitkit {◆ : Model'} (κ : Kit ◆) where 76 | \end{code} 77 | %<*kit> 78 | \begin{code} 79 | kit : {Γ Δ : List Type} → (∀ {σ} → Var σ Γ → ◆ σ Δ) → (∀ {σ} → Tm σ Γ → Tm σ Δ) 80 | kit ρ (`var v) = Kit.var κ (ρ v) 81 | kit ρ (f `$ t) = kit ρ f `$ kit ρ t 82 | kit ρ (`λ b) = `λ (kit ((Kit.wkn κ ∘ ρ) -, Kit.zro κ) b) 83 | \end{code} 84 | % 85 | \begin{code} 86 | where 87 | 88 | _-,_ : ∀ {Γ σ Δ} → (∀ {τ} → Var τ Γ → ◆ τ Δ) → ◆ σ Δ → ∀ {τ} → Var τ (σ ∷ Γ) → ◆ τ Δ 89 | (ρ -, v) ze = v 90 | (ρ -, v) (su k) = ρ k 91 | 92 | Val : Model' 93 | Val base Γ = Tm base Γ 94 | Val (arr σ τ) Γ = ∀ {Δ} → (∀ {ν} → Var ν Γ → Var ν Δ) → Val σ Δ → Val τ Δ 95 | 96 | wk : ∀ {Γ Δ} → (∀ {σ} → Var σ Γ → Var σ Δ) → ∀ {σ} → Val σ Γ → Val σ Δ 97 | wk ρ {base} v = ren ρ v 98 | wk ρ {arr σ τ} v = λ ρ′ → v (ρ′ ∘ ρ) 99 | 100 | APP : ∀ {σ τ Γ} → Val (arr σ τ) Γ → Val σ Γ → Val τ Γ 101 | APP f t = f id t 102 | 103 | LAM : ∀ {Γ σ τ} → Val (arr σ τ) Γ → Val (arr σ τ) Γ 104 | LAM = id 105 | \end{code} 106 | %<*nbe> 107 | \begin{code} 108 | nbe : {Γ Δ : List Type} → (∀ {σ} → Var σ Γ → Val σ Δ) → (∀ {σ} → Tm σ Γ → Val σ Δ) 109 | nbe ρ (`var v) = ρ v 110 | nbe ρ (f `$ t) = APP (nbe ρ f) (nbe ρ t) 111 | nbe ρ (`λ t) = LAM (λ re v → nbe ((wk re ∘ ρ) -, v) t) 112 | \end{code} 113 | % 114 | \begin{code} 115 | where 116 | 117 | _-,_ : ∀ {Γ σ Δ} → (∀ {τ} → Var τ Γ → Val τ Δ) → Val σ Δ → ∀ {τ} → Var τ (σ ∷ Γ) → Val τ Δ 118 | (ρ -, v) ze = v 119 | (ρ -, v) (su k) = ρ k 120 | \end{code} 121 | 122 | 123 | \begin{code} 124 | open import Level 125 | open import models as M 126 | 127 | module Goal {𝓥 𝓒 : Model zero} (𝓢 : Semantics 𝓥 𝓒) where 128 | \end{code} 129 | 130 | %<*sem> 131 | \begin{code} 132 | throwawaygoal : {Γ : Cx Ty} → [ (Γ -Env) 𝓥 ⟶ (Γ -Comp) 𝓒 ] 133 | \end{code} 134 | % 135 | \begin{code} 136 | throwawaygoal = Eval.sem 𝓢 137 | \end{code} 138 | -------------------------------------------------------------------------------- /src/Properties/Fusable/Syntactic/Instances.agda: -------------------------------------------------------------------------------- 1 | module Properties.Fusable.Syntactic.Instances where 2 | 3 | open import Syntax.Core hiding (_<$>_) 4 | open import Semantics.Environment as Env hiding (refl) 5 | open import Semantics.Syntactic.Instances 6 | open import Properties.Relation 7 | open import Properties.Fusable.Syntactic.Specification 8 | 9 | open import Function 10 | open import Relation.Binary.PropositionalEquality hiding (trans) 11 | open ≡-Reasoning 12 | 13 | fusableRenaming : 14 | SyntacticFusable SyntacticRenaming SyntacticRenaming SyntacticRenaming 15 | Equality (λ ρ^A ρ^B ρ^C → `∀[ Equality ] (trans ρ^A ρ^B) ρ^C) 16 | fusableRenaming = record 17 | { 𝓔^R‿∙ = λ ρ^R eq → pack^R $ λ { {_} zero → eq ; (1+ v) → lookup^R ρ^R v } 18 | ; 𝓔^R‿wk = λ inc ρ^R → pack^R $ cong (lookup inc) ∘ lookup^R ρ^R 19 | ; R⟦var⟧ = λ v ρ^R → cong `var $ lookup^R ρ^R v 20 | ; embed^BC = refl 21 | } 22 | 23 | fuseRenamings : ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) (inc : Renaming Γ Δ) (inc′ : Renaming Δ Θ) → 24 | rename inc′ (rename inc t) ≡ rename (trans inc inc′) t 25 | fuseRenamings t inc inc′ = Fundamental.lemma fusableRenaming t refl^R 26 | 27 | fusableRenamingSubstitution : 28 | SyntacticFusable SyntacticRenaming SyntacticSubstitution SyntacticSubstitution 29 | Equality (λ ρ^A ρ^B ρ^C → `∀[ Equality ] (trans ρ^A ρ^B) ρ^C) 30 | fusableRenamingSubstitution = record 31 | { 𝓔^R‿∙ = λ ρ^R eq → pack^R $ λ { {_} zero → eq ; (1+ v) → lookup^R ρ^R v } 32 | ; 𝓔^R‿wk = λ inc ρ^R → pack^R $ cong (rename inc) ∘ lookup^R ρ^R 33 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 34 | ; embed^BC = refl 35 | } 36 | 37 | fuseRenamingSubstitution : 38 | ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) (inc : Renaming Γ Δ) (ρ : Substitution Δ Θ) → 39 | substitute (rename inc t) ρ ≡ substitute t (trans inc ρ) 40 | fuseRenamingSubstitution t inc ρ = Fundamental.lemma fusableRenamingSubstitution t refl^R 41 | 42 | fusableSubstitutionRenaming : 43 | SyntacticFusable SyntacticSubstitution SyntacticRenaming SyntacticSubstitution 44 | (mkRModel $ λ v t → `var v ≡ t) (λ ρ^A ρ^B ρ^C → `∀[ Equality ] (rename ρ^B <$> ρ^A) ρ^C) 45 | fusableSubstitutionRenaming = record 46 | { 𝓔^R‿∙ = λ {_} {_} {_} {_} {ρ^A} {ρ^B} {ρ^C} {u^B} ρ^R eq → 47 | pack^R $ λ { {_} zero → eq ; (1+ v) → 48 | begin 49 | rename (ρ^B `∙ u^B) (rename extend (lookup ρ^A v)) 50 | ≡⟨ fuseRenamings (lookup ρ^A v) extend (ρ^B `∙ u^B) ⟩ 51 | rename ρ^B (lookup ρ^A v) 52 | ≡⟨ lookup^R ρ^R v ⟩ 53 | lookup ρ^C v 54 | ∎ } 55 | ; 𝓔^R‿wk = λ inc {ρ^A} {ρ^B} {ρ^C} ρ^R → pack^R $ λ v → 56 | begin 57 | rename (trans ρ^B inc) (lookup ρ^A v) 58 | ≡⟨ sym (fuseRenamings (lookup ρ^A v) ρ^B inc) ⟩ 59 | rename inc (rename ρ^B $ lookup ρ^A v) 60 | ≡⟨ cong (rename inc) (lookup^R ρ^R v) ⟩ 61 | rename inc (lookup ρ^C v) 62 | ∎ 63 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 64 | ; embed^BC = refl 65 | } 66 | 67 | fuseSubstitutionRenaming : 68 | ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) (ρ : Substitution Γ Δ) (inc : Renaming Δ Θ) → 69 | rename inc (substitute t ρ) ≡ substitute t (rename inc <$> ρ) 70 | fuseSubstitutionRenaming t inc ρ = Fundamental.lemma fusableSubstitutionRenaming t refl^R 71 | 72 | fusableSubstitutions : 73 | SyntacticFusable SyntacticSubstitution SyntacticSubstitution SyntacticSubstitution 74 | Equality (λ ρ^A ρ^B ρ^C → `∀[ Equality ] (flip substitute ρ^B <$> ρ^A) ρ^C) 75 | fusableSubstitutions = record 76 | { 𝓔^R‿∙ = λ {_} {_} {_} {_} {ρ^A} {ρ^B} {ρ^C} {u^B} {u^C} ρ^R eq → 77 | pack^R $ λ { {_} zero → eq ; (1+ v) → 78 | begin 79 | substitute (rename extend (lookup ρ^A v)) (ρ^B `∙ u^B) 80 | ≡⟨ fuseRenamingSubstitution (lookup ρ^A v) extend (ρ^B `∙ u^B) ⟩ 81 | substitute (lookup ρ^A v) ρ^B 82 | ≡⟨ lookup^R ρ^R v ⟩ 83 | lookup ρ^C v 84 | ∎ } 85 | ; 𝓔^R‿wk = λ inc {ρ^A} {ρ^B} {ρ^C} ρ^R → pack^R $ λ v → 86 | begin 87 | substitute (lookup ρ^A v) (rename inc <$> ρ^B) 88 | ≡⟨ sym (fuseSubstitutionRenaming (lookup ρ^A v) ρ^B inc) ⟩ 89 | rename inc (substitute (lookup ρ^A v) ρ^B) 90 | ≡⟨ cong (rename inc) (lookup^R ρ^R v) ⟩ 91 | rename inc (lookup ρ^C v) 92 | ∎ 93 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 94 | ; embed^BC = refl 95 | } 96 | 97 | fuseSubstitutions : 98 | ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) (ρ : Substitution Γ Δ) (ρ′ : Substitution Δ Θ) → 99 | substitute (substitute t ρ) ρ′ ≡ substitute t (flip substitute ρ′ <$> ρ) 100 | fuseSubstitutions t inc ρ = Fundamental.lemma fusableSubstitutions t refl^R 101 | -------------------------------------------------------------------------------- /src/Properties/Fusable/Specification.agda: -------------------------------------------------------------------------------- 1 | module Properties.Fusable.Specification where 2 | 3 | open import Syntax.Core 4 | open import Semantics.Model 5 | open import Semantics.Environment 6 | open import Semantics.Specification hiding (module Fundamental) 7 | open import Properties.Relation 8 | 9 | record Fusable 10 | {ℓ^EA ℓ^MA ℓ^EB ℓ^MB ℓ^EC ℓ^MC ℓ^RE ℓ^REBC ℓ^RM : Level} 11 | {𝓔^A : Model ℓ^EA} {𝓔^B : Model ℓ^EB} {𝓔^C : Model ℓ^EC} 12 | {𝓜^A : Model ℓ^MA} {𝓜^B : Model ℓ^MB} {𝓜^C : Model ℓ^MC} 13 | (𝓢^A : Semantics 𝓔^A 𝓜^A) (𝓢^B : Semantics 𝓔^B 𝓜^B) (𝓢^C : Semantics 𝓔^C 𝓜^C) 14 | (𝓔^R‿BC : RModel ℓ^REBC 𝓔^B 𝓔^C) 15 | (𝓔^R : ∀ {Θ Δ Γ} → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set ℓ^RE) 16 | (𝓜^R : RModel ℓ^RM 𝓜^B 𝓜^C) 17 | : Set (ℓ^RM ⊔ ℓ^RE ⊔ ℓ^EC ⊔ ℓ^EB ⊔ ℓ^EA ⊔ ℓ^MA ⊔ ℓ^REBC) where 18 | 19 | -- Semantics 20 | module 𝓢^A = Semantics 𝓢^A 21 | module 𝓢^B = Semantics 𝓢^B 22 | module 𝓢^C = Semantics 𝓢^C 23 | 24 | field 25 | 26 | reify^A : ∀ {Γ σ} → 𝓜^A Γ σ → Γ ⊢ σ 27 | 28 | -- We interrupt the list of fields here to introduce a handy 29 | -- notation describing the generic way in which 𝓜^R is used 30 | -- throughout the definition 31 | 32 | 𝓡 : ∀ {Γ Δ Θ σ} → Γ ⊢ σ → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set _ 33 | 𝓡 t ρ^A ρ^B ρ^C = 34 | let open Semantics.Specification.Fundamental in 35 | related 𝓜^R (lemma 𝓢^B (reify^A (lemma 𝓢^A t ρ^A)) ρ^B) (lemma 𝓢^C t ρ^C) 36 | 37 | -- We can now go back to the specification of the Fusable 38 | -- Semantics. 39 | 40 | field 41 | 42 | 𝓔^R‿∙ : ∀ {Γ Δ Θ σ} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} → ∀ {ρ^B ρ^C u^B} {u^C : 𝓔^C Θ σ} → 43 | 𝓔^R ρ^A ρ^B ρ^C → related 𝓔^R‿BC u^B u^C → 44 | 𝓔^R (wk[ 𝓢^A.wk ] extend ρ^A `∙ lookup 𝓢^A.embed zero) 45 | (ρ^B `∙ u^B) (ρ^C `∙ u^C) 46 | 47 | 𝓔^R‿wk : ∀ {Γ Δ Θ E} (inc : Renaming Θ E) → {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} → ∀ {ρ^B ρ^C} → 48 | 𝓔^R ρ^A ρ^B ρ^C → 𝓔^R ρ^A (wk[ 𝓢^B.wk ] inc ρ^B) (wk[ 𝓢^C.wk ] inc ρ^C) 49 | 50 | R⟦var⟧ : ∀ {Γ Δ Θ σ} (v : σ ∈ Γ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 51 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 (`var v) ρ^A ρ^B ρ^C 52 | 53 | R⟦λ⟧ : ∀ {Γ Δ Θ σ τ} (b : Γ ∙ σ ⊢ τ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 54 | 𝓔^R ρ^A ρ^B ρ^C → 55 | (r : ∀ {E} (inc : Renaming Θ E) → ∀ {u^B u^C} → related 𝓔^R‿BC u^B u^C → 56 | let ρ^A′ = wk[ 𝓢^A.wk ] extend ρ^A `∙ lookup 𝓢^A.embed zero 57 | ρ^B′ = wk[ 𝓢^B.wk ] inc ρ^B `∙ u^B 58 | ρ^C′ = wk[ 𝓢^C.wk ] inc ρ^C `∙ u^C 59 | in 𝓡 b ρ^A′ ρ^B′ ρ^C′) → 60 | 𝓡 (`λ b) ρ^A ρ^B ρ^C 61 | 62 | R⟦$⟧ : ∀ {Γ Δ Θ σ τ} (f : Γ ⊢ σ `→ τ) (t : Γ ⊢ σ) → 63 | ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 𝓔^R ρ^A ρ^B ρ^C → 64 | 𝓡 f ρ^A ρ^B ρ^C → 𝓡 t ρ^A ρ^B ρ^C → 𝓡 (f `$ t) ρ^A ρ^B ρ^C 65 | 66 | R⟦⟨⟩⟧ : ∀ {Γ Δ Θ} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → ∀ {ρ^C} → 67 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 `⟨⟩ ρ^A ρ^B ρ^C 68 | R⟦tt⟧ : ∀ {Γ Δ Θ} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → ∀ {ρ^C} → 69 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 `tt ρ^A ρ^B ρ^C 70 | R⟦ff⟧ : ∀ {Γ Δ Θ} {ρ^A : Var Γ ⇒[ 𝓔^A ] Δ} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → ∀ {ρ^C} → 71 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 `ff ρ^A ρ^B ρ^C 72 | 73 | R⟦ifte⟧ : ∀ {Γ Δ Θ σ} (b : Γ ⊢ `Bool) (l r : Γ ⊢ σ) → 74 | ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 𝓔^R ρ^A ρ^B ρ^C → 75 | 𝓡 b ρ^A ρ^B ρ^C → 𝓡 l ρ^A ρ^B ρ^C → 𝓡 r ρ^A ρ^B ρ^C → 76 | 𝓡 (`ifte b l r) ρ^A ρ^B ρ^C 77 | 78 | module Fundamental 79 | {ℓ^EA ℓ^MA ℓ^EB ℓ^MB ℓ^EC ℓ^MC ℓ^RE ℓ^REBC ℓ^RM : Level} 80 | {𝓔^A : Model ℓ^EA} {𝓔^B : Model ℓ^EB} {𝓔^C : Model ℓ^EC} 81 | {𝓜^A : Model ℓ^MA} {𝓜^B : Model ℓ^MB} {𝓜^C : Model ℓ^MC} 82 | {𝓢^A : Semantics 𝓔^A 𝓜^A} {𝓢^B : Semantics 𝓔^B 𝓜^B} {𝓢^C : Semantics 𝓔^C 𝓜^C} 83 | {𝓔^R‿BC : RModel ℓ^REBC 𝓔^B 𝓔^C} 84 | {𝓔^R : ∀ {Θ Δ Γ} → Var Γ ⇒[ 𝓔^A ] Δ → Var Δ ⇒[ 𝓔^B ] Θ → Var Γ ⇒[ 𝓔^C ] Θ → Set ℓ^RE} 85 | {𝓜^R : RModel ℓ^RM 𝓜^B 𝓜^C} 86 | (𝓕 : Fusable 𝓢^A 𝓢^B 𝓢^C 𝓔^R‿BC 𝓔^R 𝓜^R) 87 | where 88 | 89 | open Fusable 𝓕 90 | 91 | lemma : ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ 𝓔^B ] Θ} → 92 | 𝓔^R ρ^A ρ^B ρ^C → 𝓡 t ρ^A ρ^B ρ^C 93 | lemma (`var v) ρ^R = R⟦var⟧ v ρ^R 94 | lemma (f `$ t) ρ^R = R⟦$⟧ f t ρ^R (lemma f ρ^R) (lemma t ρ^R) 95 | lemma (`λ t) ρ^R = R⟦λ⟧ t ρ^R (λ inc u^R → lemma t (𝓔^R‿∙ (𝓔^R‿wk inc ρ^R) u^R)) 96 | lemma `⟨⟩ ρ^R = R⟦⟨⟩⟧ ρ^R 97 | lemma `tt ρ^R = R⟦tt⟧ ρ^R 98 | lemma `ff ρ^R = R⟦ff⟧ ρ^R 99 | lemma (`ifte b l r) ρ^R = R⟦ifte⟧ b l r ρ^R (lemma b ρ^R) (lemma l ρ^R) (lemma r ρ^R) 100 | -------------------------------------------------------------------------------- /doc/slides.tex: -------------------------------------------------------------------------------- 1 | \documentclass[xetex, mathserif, serif]{beamer} 2 | \usepackage[english]{babel} 3 | \usepackage[references]{agda} 4 | \setmainfont[Ligatures=TeX]{XITS} 5 | \setmathfont{XITS Math} 6 | \usepackage{catchfilebetweentags} 7 | \usepackage{graphicx} 8 | \setlength\mathindent{-1.5em} 9 | 10 | \title{Type and Scope Preserving Semantics} 11 | \titlegraphic{\hfill \includegraphics{colour-science.pdf}} 12 | \author[me]{Guillaume Allais\\[1em] James Chapman \and Conor McBride} 13 | \institute{University of Strathclyde} 14 | \date{SPLS, 2015-10-21} 15 | 16 | 17 | \begin{document} 18 | 19 | \begin{frame} 20 | \titlepage 21 | \end{frame} 22 | 23 | \begin{frame}\frametitle{Motivations} 24 | \begin{itemize} 25 | \item Formally studying PLs 26 | \begin{itemize} 27 | \item Representation of Terms / Typing derivations 28 | \item With good properties: closed under renaming and substitution, normalising 29 | \item Themselves with good properties 30 | \end{itemize} 31 | \item Writing DSLs 32 | \begin{itemize} 33 | \item Strong guarantees (type, scope safety) 34 | \item With ASTs we can inspect (optimise, compile) 35 | \end{itemize} 36 | \end{itemize} 37 | \end{frame} 38 | 39 | \begin{frame}\frametitle{Simple Types} 40 | Minimal system: A record type, a sum type and function spaces. 41 | 42 | \ExecuteMetaData[models.tex]{ty}\unskip 43 | \ExecuteMetaData[models.tex]{context}\unskip 44 | \end{frame} 45 | 46 | \begin{frame}\frametitle{Deep Embedding - Variables} 47 | Typed de Bruijn indices 48 | 49 | \ExecuteMetaData[models.tex]{var}\unskip 50 | \end{frame} 51 | \begin{frame}\frametitle{Deep Embedding - Terms} 52 | ASTs type and scope correct by construction 53 | 54 | \ExecuteMetaData[models.tex]{term}\unskip 55 | \end{frame} 56 | 57 | \begin{frame}\frametitle{Goguen \& McKinna: Conspicuously similar functions} 58 | \only<1>{\ExecuteMetaData[usual.tex]{rename}}\unskip 59 | \only<2>{\ExecuteMetaData[usual.tex]{subst}}\unskip 60 | \end{frame} 61 | 62 | \begin{frame}\frametitle{Factoring Out the Common Parts} 63 | \ExecuteMetaData[models.tex]{syntactic}\unskip 64 | \end{frame} 65 | 66 | \begin{frame}\frametitle{Implementing the traversal Once and For All} 67 | \ExecuteMetaData[usual.tex]{syn}\unskip 68 | \ExecuteMetaData[usual.tex]{synextend}\unskip 69 | \end{frame} 70 | 71 | \begin{frame}\frametitle{Is that it? Not quite.} 72 | \begin{itemize} 73 | \item Other interesting instance? 74 | \item Properties of these traversals? (4 fusion lemmas) 75 | \item What if I don't program in Agda? 76 | \item Generic boilerplate for all syntaxes with binding? 77 | \end{itemize} 78 | \end{frame} 79 | 80 | \begin{frame}\frametitle{Normalisation by Evaluation's ``eval''} 81 | \only<1>{\ExecuteMetaData[usual.tex]{sem}}\unskip 82 | \only<2>{\ExecuteMetaData[usual.tex]{subst}}\unskip 83 | \end{frame} 84 | 85 | \begin{frame}\frametitle{An Abstract Notion of Semantics} 86 | \ExecuteMetaData[usual.tex]{semantics} 87 | \end{frame} 88 | 89 | \begin{frame}\frametitle{And a Fundamental Lemma} 90 | \ExecuteMetaData[models.tex]{evaluation} 91 | \end{frame} 92 | 93 | \begin{frame}\frametitle{Various Instances} 94 | \ExecuteMetaData[usual.tex]{semexamples} 95 | \end{frame} 96 | 97 | \begin{frame}\frametitle{Is that it? Not quite.} 98 | \begin{itemize} 99 | \item \textcolor{gray}{Other interesting instance?} 100 | \item Properties of these traversals? (4 fusion lemmas) 101 | \item What if I don't program in Agda? 102 | \item Generic boilerplate for all syntaxes with binding? 103 | \end{itemize} 104 | \end{frame} 105 | 106 | \begin{frame}{A Relational Interpretation} 107 | \ExecuteMetaData[usual.tex]{synchronisable} 108 | \end{frame} 109 | 110 | \begin{frame}{And a Fundamental Lemma} 111 | \ExecuteMetaData[models.tex]{relational} 112 | \end{frame} 113 | 114 | \begin{frame}{An interesting corollary} 115 | \ExecuteMetaData[models.tex]{synchroexample} 116 | \ExecuteMetaData[models.tex]{synchroexample2} 117 | \end{frame} 118 | 119 | \begin{frame}{Is that it? Not quite.} 120 | \begin{itemize} 121 | \item \textcolor{gray}{Other interesting instance?} 122 | \item \textcolor{gray}{Properties of these traversals? (4 fusion lemmas)} 123 | \item What if I don't program in Agda? 124 | \item Generic boilerplate for all syntaxes with binding? 125 | \end{itemize} 126 | \end{frame} 127 | 128 | \begin{frame}{Using this somewhere else} 129 | The programming part of this talk can be implemented in Haskell: 130 | {\small\url{https://github.com/gallais/type-scope-semantics/}} 131 | \end{frame} 132 | 133 | \begin{frame}{Is that it? Not quite.} 134 | \begin{itemize} 135 | \item \textcolor{gray}{Other interesting instance?} 136 | \item \textcolor{gray}{Properties of these traversals? (4 fusion lemmas)} 137 | \item \textcolor{gray}{What if I don't program in Agda?} 138 | \item Generic boilerplate for all syntaxes with binding? 139 | \end{itemize} 140 | \end{frame} 141 | 142 | \end{document} 143 | -------------------------------------------------------------------------------- /doc/2017-01-17.tex: -------------------------------------------------------------------------------- 1 | \documentclass[xetex, mathserif, serif]{beamer} 2 | 3 | %% Using the Radboud Uni theme. If you don't have it, comment 4 | %% out this line. Or get it here: 5 | %% https://gitlab.science.ru.nl/benoit/rutheme 6 | \usetheme{ru} 7 | 8 | \usepackage[english]{babel} 9 | \usepackage[references]{agda} 10 | \setmainfont[Ligatures=TeX]{XITS} 11 | \setmathfont{XITS Math} 12 | \usepackage{catchfilebetweentags} 13 | \usepackage{graphicx} 14 | \setlength\mathindent{-1.5em} 15 | 16 | \title{Type-and-Scope Safe Programs and their Proofs} 17 | \author[me]{\underline{Guillaume Allais} \and James Chapman \and Conor McBride \and James McKinna} 18 | \institute{} 19 | \date{CPP, 2017-01-17} 20 | 21 | 22 | \begin{document} 23 | 24 | \begin{frame} 25 | \titlepage 26 | \end{frame} 27 | 28 | \begin{frame}\frametitle{Motivations} 29 | \begin{itemize} 30 | \item Formally studying PLs 31 | \begin{itemize} 32 | \item Representation of Terms / Typing derivations 33 | \item With good properties: closed under renaming and substitution, normalising 34 | \item Themselves with good properties 35 | \end{itemize} 36 | \item Writing DSLs 37 | \begin{itemize} 38 | \item Strong guarantees (type, scope safety) 39 | \item With ASTs we can inspect (optimise, compile) 40 | \end{itemize} 41 | \end{itemize} 42 | \end{frame} 43 | 44 | \begin{frame}\frametitle{Simple Types} 45 | Minimal system: A record type, a sum type and function spaces. 46 | 47 | \ExecuteMetaData[models.tex]{ty}\unskip 48 | \ExecuteMetaData[models.tex]{context}\unskip 49 | \end{frame} 50 | 51 | \begin{frame}\frametitle{Deep Embedding - Variables} 52 | Typed de Bruijn indices 53 | 54 | \ExecuteMetaData[models.tex]{var}\unskip 55 | \end{frame} 56 | \begin{frame}\frametitle{Deep Embedding - Terms} 57 | ASTs type and scope correct by construction 58 | 59 | \ExecuteMetaData[models.tex]{term}\unskip 60 | \end{frame} 61 | 62 | \begin{frame}{A Generic Notion of Environment} 63 | \ExecuteMetaData[models.tex]{environment}\unskip 64 | \end{frame} 65 | 66 | % onslide / only are not working with the RU theme for some reason. 67 | \begin{frame}\frametitle{Goguen \& McKinna: Conspicuously similar functions} 68 | \ExecuteMetaData[usual.tex]{rename} 69 | \end{frame} 70 | \begin{frame}\frametitle{Goguen \& McKinna: Conspicuously similar functions} 71 | \ExecuteMetaData[usual.tex]{subst} 72 | \end{frame} 73 | 74 | \begin{frame}\frametitle{Factoring Out the Common Parts} 75 | % Comment on Kripke / NBE 76 | \ExecuteMetaData[models.tex]{box}\unskip 77 | \ExecuteMetaData[models.tex]{thinnable}\unskip 78 | \ExecuteMetaData[models.tex]{syntactic}\unskip 79 | \end{frame} 80 | 81 | \begin{frame}\frametitle{Implementing the traversal Once and For All} 82 | \ExecuteMetaData[usual.tex]{syn}\unskip 83 | \ExecuteMetaData[usual.tex]{synextend}\unskip 84 | \end{frame} 85 | 86 | \begin{frame}\frametitle{Is that it? Not quite.} 87 | \begin{itemize} 88 | \item Other interesting instance? 89 | \item Properties of these traversals? (2*n fusion lemmas) 90 | \item What if I don't program in Agda? 91 | \item Generic boilerplate for all syntaxes with binding? 92 | \end{itemize} 93 | \end{frame} 94 | 95 | \begin{frame}\frametitle{Normalisation by Evaluation's ``eval''} 96 | \ExecuteMetaData[models.tex]{box}\vspace{-3em} 97 | \ExecuteMetaData[usual.tex]{kripkemodel} 98 | \ExecuteMetaData[usual.tex]{sem} 99 | \end{frame} 100 | \begin{frame}\frametitle{Normalisation by Evaluation's ``eval''} 101 | \ExecuteMetaData[usual.tex]{subst} 102 | \end{frame} 103 | 104 | 105 | \begin{frame}\frametitle{An Abstract Notion of Semantics} 106 | \ExecuteMetaData[usual.tex]{semantics} 107 | \end{frame} 108 | 109 | \begin{frame}\frametitle{And a Fundamental Lemma} 110 | \ExecuteMetaData[models.tex]{comp} 111 | \ExecuteMetaData[models.tex]{semtype}\vspace{-1.5em} 112 | \ExecuteMetaData[models.tex]{evaluation} 113 | \ExecuteMetaData[models.tex]{semextend} 114 | \end{frame} 115 | 116 | \begin{frame}\frametitle{Various Instances} 117 | \ExecuteMetaData[usual.tex]{semexamples} 118 | \end{frame} 119 | 120 | \begin{frame}\frametitle{Is that it? Not quite.} 121 | \begin{itemize} 122 | \item \textcolor{gray}{Other interesting instance?} 123 | \item Properties of these traversals? (2*n fusion lemmas) 124 | \item What if I don't program in Agda? 125 | \item Generic boilerplate for all syntaxes with binding? 126 | \end{itemize} 127 | \end{frame} 128 | 129 | \begin{frame}{A Relational Interpretation} 130 | \ExecuteMetaData[models.tex]{relmodel}\vspace{-2.5em} 131 | \ExecuteMetaData[usual.tex]{synchronisable} 132 | \end{frame} 133 | 134 | \begin{frame}{And a Fundamental Lemma} 135 | \ExecuteMetaData[models.tex]{relational} 136 | \end{frame} 137 | 138 | \begin{frame}{An interesting corollary} 139 | \ExecuteMetaData[models.tex]{synchroexample} 140 | \ExecuteMetaData[usual.tex]{synchroexample2} 141 | \end{frame} 142 | 143 | \begin{frame}{A Generic Fusion Theorem} 144 | \ExecuteMetaData[models.tex]{renren}\vspace{-1.8em} 145 | \ExecuteMetaData[models.tex]{subren}\vspace{-1.8em} 146 | \ExecuteMetaData[models.tex]{rensub}\vspace{-1.8em} 147 | \ExecuteMetaData[models.tex]{subsub} 148 | \ExecuteMetaData[models.tex]{subnbe}\unskip 149 | \end{frame} 150 | 151 | \begin{frame}{Is that it? Not quite.} 152 | \begin{itemize} 153 | \item \textcolor{gray}{Other interesting instance?} 154 | \item \textcolor{gray}{Properties of these traversals? (2*n fusion lemmas)} 155 | \item What if I don't program in Agda? 156 | \item Generic boilerplate for all syntaxes with binding? 157 | \end{itemize} 158 | \end{frame} 159 | 160 | \begin{frame}{Using this somewhere else} 161 | The programming part of this talk can be implemented in Haskell: 162 | {\small\url{https://github.com/gallais/type-scope-semantics/}} 163 | \end{frame} 164 | 165 | \begin{frame}{Is that it? Not quite.} 166 | \begin{itemize} 167 | \item \textcolor{gray}{Other interesting instance?} 168 | \item \textcolor{gray}{Properties of these traversals? (2*n fusion lemmas)} 169 | \item \textcolor{gray}{What if I don't program in Agda?} 170 | \item Generic boilerplate for all syntaxes with binding? 171 | \end{itemize} 172 | \end{frame} 173 | 174 | \end{document} 175 | -------------------------------------------------------------------------------- /doc/usual.lagda: -------------------------------------------------------------------------------- 1 | \documentclass[xetex, mathserif, serif]{beamer} 2 | \usepackage[utf8]{inputenc} 3 | \usepackage[english]{babel} 4 | \usepackage[references]{agda} 5 | \setmainfont[Ligatures=TeX]{XITS} 6 | \setmathfont{XITS Math} 7 | \usepackage{newunicodechar} 8 | \usepackage{amssymb} 9 | 10 | \begin{code} 11 | module usual where 12 | 13 | open import models hiding (Semantics ; module Semantics ; Simulation ; module Simulation ; Fusable ; Renaming ; Substitution ; Printing ; CPS^N) 14 | open import Data.Unit 15 | open import Data.Bool 16 | open import Function 17 | 18 | import Level as L 19 | `Model : Set₁ 20 | `Model = Model {Ty} L.zero 21 | 22 | module PrivateKr where 23 | 24 | Kr : `Model 25 | Kr `1 = const ⊤ 26 | Kr `2 = const ⊤ 27 | \end{code} 28 | %<*kripkemodel> 29 | \begin{code} 30 | Kr (σ `→ τ) = □ (Kr σ ⟶ Kr τ) 31 | \end{code} 32 | % 33 | \begin{code} 34 | `RModel : `Model → `Model → Set₁ 35 | `RModel 𝓥 𝓒 = RModel 𝓥 𝓒 L.zero 36 | 37 | ren⟦var⟧ : ∀ {σ} → [ Var σ ⟶ Tm σ ] 38 | ren⟦var⟧ = `var 39 | 40 | renextend : {Γ Δ : Cx Ty} {σ : Ty} (ρ : (Γ -Env) Var Δ) → (Γ ∙ σ -Env) Var (Δ ∙ σ) 41 | renextend = pop! 42 | 43 | \end{code} 44 | %<*rename> 45 | \begin{code} 46 | ren : {Γ Δ : Cx Ty} {σ : Ty} → (Γ -Env) Var Δ → Tm σ Γ → Tm σ Δ 47 | ren ρ (`var v) = ren⟦var⟧ (lookup ρ v) 48 | ren ρ (t `$ u) = ren ρ t `$ ren ρ u 49 | ren ρ (`λ t) = `λ (ren (renextend ρ) t) 50 | \end{code} 51 | % 52 | \begin{code} 53 | ren ρ `⟨⟩ = `⟨⟩ 54 | ren ρ `tt = `tt 55 | ren ρ `ff = `ff 56 | ren ρ (`if b l r) = `if (ren ρ b) (ren ρ l) (ren ρ r) 57 | 58 | subextend : {Γ Δ : Cx Ty} {σ : Ty} (ρ : (Γ -Env) Tm Δ) → (Γ ∙ σ -Env) Tm (Δ ∙ σ) 59 | subextend ρ = th[ th^Tm ] (pack su) ρ `∙ `var ze 60 | 61 | sub⟦var⟧ = id 62 | \end{code} 63 | %<*subst> 64 | \begin{code} 65 | sub : {Γ Δ : Cx Ty} {σ : Ty} → (Γ -Env) Tm Δ → Tm σ Γ → Tm σ Δ 66 | sub ρ (`var v) = sub⟦var⟧ (lookup ρ v) 67 | sub ρ (t `$ u) = sub ρ t `$ sub ρ u 68 | sub ρ (`λ t) = `λ (sub (subextend ρ) t) 69 | \end{code} 70 | % 71 | \begin{code} 72 | sub ρ `⟨⟩ = `⟨⟩ 73 | sub ρ `tt = `tt 74 | sub ρ `ff = `ff 75 | sub ρ (`if b l r) = `if (sub ρ b) (sub ρ l) (sub ρ r) 76 | \end{code} 77 | %<*synextend> 78 | \begin{code} 79 | synextend : ∀ {Γ Δ : Cx Ty} {σ : Ty} {𝓥 : `Model} (𝓢 : Syntactic 𝓥) → 80 | (Γ -Env) 𝓥 Δ → (Γ ∙ σ -Env) 𝓥 (Δ ∙ σ) 81 | synextend 𝓢 ρ = ρ′ `∙ var 82 | where var = Syntactic.var‿0 𝓢 83 | ρ′ = pack $ Syntactic.th 𝓢 _ (pack su) ∘ lookup ρ 84 | \end{code} 85 | % 86 | 87 | 88 | %<*syn> 89 | \begin{code} 90 | syn : {Γ Δ : Cx Ty} {σ : Ty} {𝓥 : `Model} (𝓢 : Syntactic 𝓥) → (Γ -Env) 𝓥 Δ → Tm σ Γ → Tm σ Δ 91 | syn 𝓢 ρ (`var v) = Syntactic.⟦var⟧ 𝓢 (lookup ρ v) 92 | syn 𝓢 ρ (t `$ u) = syn 𝓢 ρ t `$ syn 𝓢 ρ u 93 | syn 𝓢 ρ (`λ t) = `λ (syn 𝓢 (synextend 𝓢 ρ) t) 94 | \end{code} 95 | % 96 | \begin{code} 97 | syn 𝓢 ρ `⟨⟩ = `⟨⟩ 98 | syn 𝓢 ρ `tt = `tt 99 | syn 𝓢 ρ `ff = `ff 100 | syn 𝓢 ρ (`if b l r) = `if (syn 𝓢 ρ b) (syn 𝓢 ρ l) (syn 𝓢 ρ r) 101 | 102 | open βιξη hiding (Normalise) 103 | 104 | module sem where 105 | 106 | sem⟦var⟧ = id 107 | 108 | semλ : {Γ Δ Θ : Cx Ty} {σ τ : Ty} (b : Tm τ (Γ ∙ σ)) (⟦t⟧ : (Γ ∙ σ -Env) Kr Θ → Kr τ Θ) 109 | (ρ : Δ ⊆ Θ → Kr σ Θ → (Γ ∙ σ -Env) Kr Θ) (inc : Δ ⊆ Θ) (u : Kr σ Θ ) → Kr τ Θ 110 | semλ _ ⟦t⟧ ρ inc u = ⟦t⟧ (ρ inc u) 111 | 112 | ⟨⟩ = tt 113 | 114 | semextend : {Γ Δ Θ : Cx Ty} {σ : Ty} (ρ : (Γ -Env) Kr Δ) → Δ ⊆ Θ → Kr σ Θ → (Γ ∙ σ -Env) Kr Θ 115 | semextend ρ inc u = pack (λ {σ} → th^Kr σ inc ∘ lookup ρ) `∙ u 116 | 117 | 118 | sem$ : ∀ {Γ Δ σ τ} → Tm (σ `→ τ) Γ → Tm σ Γ → Kr (σ `→ τ) Δ → Kr σ Δ → Kr τ Δ 119 | sem$ _ _ F T = F refl T 120 | \end{code} 121 | 122 | %<*sem> 123 | \begin{code} 124 | sem : {Γ Δ : Cx Ty} {σ : Ty} → (Γ -Env) Kr Δ → Tm σ Γ → Kr σ Δ 125 | sem ρ (`var v) = sem⟦var⟧ (lookup ρ v) 126 | sem ρ (t `$ u) = sem$ t u (sem ρ t) (sem ρ u) 127 | sem ρ (`λ t) = semλ t (λ ρ → sem ρ t) (semextend ρ) 128 | \end{code} 129 | % 130 | \begin{code} 131 | sem ρ `⟨⟩ = ⟨⟩ 132 | sem ρ `tt = NormalForms.`tt 133 | sem ρ `ff = NormalForms.`ff 134 | sem {σ = σ} ρ (`if b l r) = if {σ} (sem ρ b ) (sem ρ l ) (sem ρ r ) 135 | \end{code} 136 | %<*semantics> 137 | \begin{code} 138 | record Semantics {ℓ} (𝓥 𝓒 : `Model) : Set ℓ where 139 | field 140 | \end{code}\vspace{ -2em} 141 | \uncover<2->{ 142 | \begin{code} 143 | th : ∀ σ → Thinnable (𝓥 σ) 144 | ⟦var⟧ : ∀ σ → [ 𝓥 σ ⟶ 𝓒 σ ] 145 | \end{code}}\vspace{ -2em} 146 | \uncover<3->{ 147 | \begin{code} 148 | ⟦λ⟧ : {σ τ : Ty} → [ □ (𝓥 σ ⟶ 𝓒 τ) ⟶ 𝓒 (σ `→ τ) ] 149 | _⟦$⟧_ : {σ τ : Ty} → [ 𝓒 (σ `→ τ) ⟶ 𝓒 σ ⟶ 𝓒 τ ] 150 | \end{code}}\vspace{ -2em} 151 | % 152 | \begin{code} 153 | ⟦⟨⟩⟧ : [ 𝓒 `1 ] 154 | ⟦tt⟧ : [ 𝓒 `2 ] 155 | ⟦ff⟧ : [ 𝓒 `2 ] 156 | ⟦ifte⟧ : {σ : Ty} → [ 𝓒 `2 ⟶ 𝓒 σ ⟶ 𝓒 σ ⟶ 𝓒 σ ] 157 | \end{code}} 158 | 159 | %<*semexamples> 160 | \begin{code} 161 | Renaming : models.Semantics Var Tm 162 | Substitution : models.Semantics Tm Tm 163 | \end{code}\vspace{ -2em} 164 | \uncover<2->{ 165 | \begin{code} 166 | Normalise : models.Semantics Kr Kr 167 | \end{code}}\vspace{ -2em} 168 | \uncover<3->{ 169 | \begin{code} 170 | CPS^N : models.Semantics Var^N Ml^N 171 | \end{code}}\vspace{ -2em} 172 | \uncover<4>{ 173 | \begin{code} 174 | Printing : models.Semantics Name Printer 175 | \end{code}} 176 | % 177 | 178 | \begin{code} 179 | Renaming = syntactic syntacticRenaming 180 | Substitution = syntactic syntacticSubstitution 181 | Printing = models.Printing 182 | Normalise = models.βιξη.Normalise 183 | CPS^N = models.CPS^N 184 | \end{code} 185 | 186 | %<*synchronisable> 187 | \begin{code} 188 | record Simulation 189 | {𝓥^A 𝓥^B 𝓒^A 𝓒^B : `Model} (𝓢^A : models.Semantics 𝓥^A 𝓒^A) (𝓢^B : models.Semantics 𝓥^B 𝓒^B) 190 | (𝓥^R : `RModel 𝓥^A 𝓥^B) (𝓒^R : `RModel 𝓒^A 𝓒^B) : Set where 191 | \end{code} 192 | \AgdaHide{ 193 | \begin{code} 194 | module 𝓢^A = models.Semantics 𝓢^A 195 | module 𝓢^B = models.Semantics 𝓢^B 196 | open Eval 197 | 198 | 𝓡 : {Γ Δ : Cx Ty} {σ : Ty} → Tm σ Γ → (Γ -Env) 𝓥^A Δ → (Γ -Env) 𝓥^B Δ → Set 199 | 𝓡 t ρ^A ρ^B = rmodel 𝓒^R (Eval.sem 𝓢^A ρ^A t) (Eval.sem 𝓢^B ρ^B t) 200 | 201 | field 202 | \end{code}}\vspace{ -2em} 203 | \uncover<2->{ 204 | \begin{code} 205 | 𝓥^R‿th : {Γ Δ Θ : Cx Ty} (inc : Δ ⊆ Θ) {ρ^A : (Γ -Env) 𝓥^A Δ} {ρ^B : (Γ -Env) 𝓥^B Δ} → `∀[ 𝓥^R ] ρ^A ρ^B → `∀[ 𝓥^R ] (th[ 𝓢^A.th ] inc ρ^A) (th[ 𝓢^B.th ] inc ρ^B) 206 | \end{code}}\vspace{ -2em} 207 | \uncover<3->{ 208 | \begin{code} 209 | R⟦var⟧ : {Γ Δ : Cx Ty} {σ : Ty} (v : Var σ Γ) {ρ^A : (Γ -Env) 𝓥^A Δ} {ρ^B : _} → `∀[ 𝓥^R ] ρ^A ρ^B → 𝓡 (`var v) ρ^A ρ^B 210 | \end{code}}\vspace{ -2em} 211 | \uncover<4->{ 212 | \begin{code} 213 | R⟦λ⟧ : ∀ {Γ Δ Θ : Cx Ty} {σ τ} (b : Tm τ (Γ ∙ σ)) {ρ^A : (Γ -Env) 𝓥^A Δ} {ρ^B} → 214 | (b^R : {Θ : Cx Ty} {u^A : 𝓥^A σ Θ} {u^B : 𝓥^B σ Θ} → (pr : Δ ⊆ Θ) → rmodel 𝓥^R u^A u^B → 215 | 𝓡 b (semextend 𝓢^A ρ^A pr u^A) (semextend 𝓢^B ρ^B pr u^B)) → 216 | `∀[ 𝓥^R ] ρ^A ρ^B → 𝓡 (`λ b) ρ^A ρ^B 217 | \end{code}} 218 | % 219 | 220 | %<*synchroexample2> 221 | \begin{code} 222 | refl^Kr : ∀ {Γ Δ σ} (t : Tm σ Γ) (ρ : (Γ -Env) Kr Δ) → 223 | let T = Eval.sem Normalise ρ t in 224 | `∀[ PER′ ] ρ ρ → PER σ T T 225 | refl^Kr t ρ ρ^R = Simulate.sim SimulationNormalise t ρ^R 226 | \end{code} 227 | % 228 | -------------------------------------------------------------------------------- /src/Properties/Fusable/Instances.agda: -------------------------------------------------------------------------------- 1 | module Properties.Fusable.Instances where 2 | 3 | open import Syntax.Core hiding (_<$>_) 4 | open import Syntax.Normal 5 | open import Semantics.Environment as Env hiding (refl) 6 | import Semantics.Specification 7 | open import Semantics.Instances 8 | open import Properties.Relation 9 | open import Properties.Relation.Printing 10 | open import Properties.Relation.βιξη 11 | open import Properties.Synchronisable.Instances 12 | open import Properties.Fusable.Specification 13 | open import Properties.Fusable.Syntactic.Instances public 14 | open import Data.Nat.Base using (ℕ; zero; suc) 15 | open import Data.Product 16 | open import Function as F 17 | open import Relation.Binary.PropositionalEquality as PEq hiding (trans) 18 | 19 | ifteRenNorm : 20 | ∀ {Γ Δ Θ σ} (b : Γ ⊢ `Bool) (l r : Γ ⊢ σ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ βιξη._⊨_ ] Θ} → 21 | related _≣_ (βιξη.eval (rename ρ^A b) ρ^B) (βιξη.eval b ρ^C) → 22 | related _≣_ (βιξη.eval (rename ρ^A l) ρ^B) (βιξη.eval l ρ^C) → 23 | related _≣_ (βιξη.eval (rename ρ^A r) ρ^B) (βιξη.eval r ρ^C) → 24 | related _≣_ (βιξη.eval (rename ρ^A (`ifte b l r)) ρ^B) (βιξη.eval (`ifte b l r) ρ^C) 25 | ifteRenNorm b l r {ρ^A} {ρ^C} {ρ^B} eqB eqL eqR 26 | with βιξη.eval (rename ρ^A b) ρ^B | βιξη.eval b ρ^C 27 | ifteRenNorm b l r refl eqL eqR | `neu pr ne | .(`neu pr ne) = 28 | reflect^≣ _ $ cong₂ (`ifte ne) (reify^≣ _ eqL) (reify^≣ _ eqR) 29 | ifteRenNorm b l r refl eqL eqR | `tt | .`tt = eqL 30 | ifteRenNorm b l r refl eqL eqR | `ff | .`ff = eqR 31 | 32 | fusableRenamingNormalise : 33 | Fusable 𝓢^Renaming βιξη.Normalise βιξη.Normalise 34 | _≣_ (λ ρ^A ρ^B ρ^C → `∀[ _≣_ ] (trans ρ^A ρ^B) ρ^C) _≣_ 35 | fusableRenamingNormalise = record 36 | { reify^A = id 37 | ; 𝓔^R‿∙ = λ ρ^R u^R → lookup^R ρ^R ∙^R′ u^R 38 | ; 𝓔^R‿wk = λ inc ρ^R → pack^R $ wk^≣ inc ∘ lookup^R ρ^R 39 | ; R⟦var⟧ = λ v ρ^R → lookup^R ρ^R v 40 | ; R⟦λ⟧ = λ b ρ^R r → r 41 | ; R⟦$⟧ = λ f t ρ^R F T → F Env.refl T 42 | ; R⟦⟨⟩⟧ = const _ 43 | ; R⟦tt⟧ = const PEq.refl 44 | ; R⟦ff⟧ = const PEq.refl 45 | ; R⟦ifte⟧ = λ b l r _ → ifteRenNorm b l r 46 | } 47 | 48 | fuseRenamingEvaluate : 49 | ∀ {Γ Δ Θ σ} (t : Γ ⊢ σ) (inc : Renaming Γ Δ) (ρ : Var Δ ⇒[ βιξη._⊨_ ] Θ) → 50 | `∀[ _≣_ ] ρ ρ → 51 | EQREL Θ σ (βιξη.eval (rename inc t) ρ) (βιξη.eval t (trans inc ρ)) 52 | fuseRenamingEvaluate t inc ρ ρ^R = 53 | Fundamental.lemma fusableRenamingNormalise t $ pack^R $ lookup^R ρ^R ∘ lookup inc 54 | 55 | fuseRenamingNormalise : 56 | ∀ {Γ Δ σ} (t : Γ ⊢ σ) (inc : Renaming Γ Δ) → 57 | βιξη.norm' (rename inc t) ≡ 58 | βιξη.reify _ (βιξη.eval t ((βιξη.reflect _ ∘ `var) <$> inc)) 59 | fuseRenamingNormalise t inc = 60 | reify^≣ _ $ Fundamental.lemma fusableRenamingNormalise t 61 | $ pack^R $ λ v → reflect^≣ _ PEq.refl 62 | 63 | ifteSubNorm : 64 | ∀ {Γ Δ Θ σ} (b : Γ ⊢ `Bool) (l r : Γ ⊢ σ) → ∀ {ρ^A ρ^C} {ρ^B : Var Δ ⇒[ βιξη._⊨_ ] Θ} → 65 | related _≣_ (βιξη.eval (substitute b ρ^A) ρ^B) (βιξη.eval b ρ^C) → 66 | related _≣_ (βιξη.eval (substitute l ρ^A) ρ^B) (βιξη.eval l ρ^C) → 67 | related _≣_ (βιξη.eval (substitute r ρ^A) ρ^B) (βιξη.eval r ρ^C) → 68 | related _≣_ (βιξη.eval (substitute (`ifte b l r) ρ^A) ρ^B) (βιξη.eval (`ifte b l r) ρ^C) 69 | ifteSubNorm b l r {ρ^A} {ρ^C} {ρ^B} eqB eqL eqR 70 | with βιξη.eval (substitute b ρ^A) ρ^B | βιξη.eval b ρ^C 71 | ifteSubNorm b l r refl eqL eqR | `neu pr ne | .(`neu pr ne) = 72 | reflect^≣ _ $ cong₂ (`ifte ne) (reify^≣ _ eqL) (reify^≣ _ eqR) 73 | ifteSubNorm b l r refl eqL eqR | `tt | .`tt = eqL 74 | ifteSubNorm b l r refl eqL eqR | `ff | .`ff = eqR 75 | 76 | fusableSubstitutionNormalise : 77 | Fusable 𝓢^Substitution βιξη.Normalise βιξη.Normalise 78 | _≣_ (λ ρ^A ρ^B ρ^C → `∀[ _≣_ ] ρ^B ρ^B 79 | × (∀ {Ω} (inc : Renaming _ Ω) → 80 | `∀[ _≣_ ] (flip βιξη.eval (βιξη.wk^⊨ inc <$> ρ^B) <$> ρ^A) (βιξη.wk^⊨ inc <$> ρ^C)) 81 | × `∀[ _≣_ ] (flip βιξη.eval ρ^B <$> ρ^A) ρ^C) 82 | _≣_ 83 | fusableSubstitutionNormalise = record 84 | { reify^A = id 85 | ; 𝓔^R‿∙ = λ {_ _ _ _ ρ^A ρ^B ρ^C} ρ^R u^R → 86 | let (ρ^R₁ , ρ^R₂ , ρ^R₃) = ρ^R 87 | ρ^R₁′ = ρ^R₁ ∙^R refl≣ u^R 88 | in ρ^R₁′ 89 | , (λ inc → 90 | let ρ^R′ = λ {σ} (v : σ ∈ _) → 91 | let env^R = pack^R $ λ v → wk^≣ inc (lookup^R ρ^R₁′ v) 92 | in trans≣ (fuseRenamingEvaluate (lookup ρ^A v) extend _ env^R) 93 | (lookup^R (ρ^R₂ inc) v) 94 | in ρ^R′ ∙^R′ wk^≣ inc u^R) 95 | , let ρ^R′ = λ {σ} (v : σ ∈ _) → 96 | trans≣ (fuseRenamingEvaluate (lookup ρ^A v) extend _ ρ^R₁′) 97 | (lookup^R ρ^R₃ v) 98 | in ρ^R′ ∙^R′ u^R 99 | ; 𝓔^R‿wk = λ {Γ Δ Θ} inc {ρ^A ρ^B ρ^C} ρ^R → 100 | let (ρ^R₁ , ρ^R₂ , ρ^R₃) = ρ^R 101 | in (pack^R $ λ v → wk^≣ inc $ lookup^R ρ^R₁ v) 102 | , (λ {Ω} inc′ → 103 | let INC : Renaming Θ Ω 104 | INC = Env.trans inc inc′ 105 | wkρ^B : Var Δ ⇒[ βιξη._⊨_ ] Ω 106 | -- for some reason using <$> breaks inference 107 | wkρ^B = pack $ λ v → βιξη.wk^⊨ inc′ $ βιξη.wk^⊨ inc $ lookup ρ^B v 108 | ρ^R′ : `∀[ _≣_ ] wkρ^B (βιξη.wk^⊨ INC <$> ρ^B) 109 | ρ^R′ = pack^R $ λ v → wk^⊨-trans inc inc′ (lookup^R ρ^R₁ v) 110 | in pack^R $ λ v → 111 | trans≣ (refl^βιξη (lookup ρ^A v) ρ^R′) 112 | $ trans≣ (lookup^R (ρ^R₂ INC) v) 113 | $ sym≣ $ wk^⊨-trans inc inc′ $ refl≣ $ sym≣ $ lookup^R ρ^R₃ v) 114 | , ρ^R₂ inc 115 | ; R⟦var⟧ = λ v ρ^R → lookup^R (proj₂ ∘ proj₂ $ ρ^R) v 116 | ; R⟦λ⟧ = λ _ _ r → r 117 | ; R⟦$⟧ = λ _ _ _ r → r Env.refl 118 | ; R⟦⟨⟩⟧ = λ _ → _ 119 | ; R⟦tt⟧ = const PEq.refl 120 | ; R⟦ff⟧ = const PEq.refl 121 | ; R⟦ifte⟧ = λ b l r _ → ifteSubNorm b l r 122 | } 123 | 124 | open import Codata.Thunk 125 | open import Codata.Stream 126 | 127 | fusableRenamingPrinting : 128 | Fusable 𝓢^Renaming Printing Printing 129 | Equality (λ ρ^A ρ^B → `∀[ Equality ] (trans ρ^A ρ^B)) _≈_ 130 | fusableRenamingPrinting = record 131 | { reify^A = id 132 | ; 𝓔^R‿∙ = λ ρ^R eq → lookup^R ρ^R ∙^R′ eq 133 | ; 𝓔^R‿wk = λ inc ρ^R → pack^R $ λ v → cong (mkName ∘ runName) $ lookup^R ρ^R v 134 | ; R⟦var⟧ = λ v ρ^R → cong₂ (_,_ ∘ runName) (lookup^R ρ^R v) 135 | ; R⟦λ⟧ = λ {_ _ Θ σ} t ρ^R r → λ { {n₁ ∷ n₁s} {n₂ ∷ n₂s} eq → 136 | let (neq , nseq) = ∷-inj eq 137 | inc : Renaming Θ (Θ ∙ σ) 138 | inc = extend 139 | (ihstr , ihns) = ,-inj (r inc (cong mkName neq) nseq) 140 | in cong₂ _,_ (cong₂ formatλ neq ihstr) ihns} 141 | ; R⟦$⟧ = λ _ _ _ ihf iht eq → 142 | let (ihstrf , eq₁) = ,-inj (ihf eq) 143 | (ihstrt , eq₂) = ,-inj (iht eq₁) 144 | in cong₂ _,_ (cong₂ format$ ihstrf ihstrt) eq₂ 145 | ; R⟦⟨⟩⟧ = λ _ → cong _ 146 | ; R⟦tt⟧ = λ _ → cong _ 147 | ; R⟦ff⟧ = λ _ → cong _ 148 | ; R⟦ifte⟧ = λ _ _ _ _ ihb ihl ihr eq → 149 | let (ihstrb , eq₁) = ,-inj (ihb eq) 150 | (ihstrl , eq₂) = ,-inj (ihl eq₁) 151 | (ihstrr , eq₃) = ,-inj (ihr eq₂) 152 | in cong₂ _,_ (cong₂ (uncurry formatIf) (cong₂ _,_ ihstrb ihstrl) ihstrr) eq₃ 153 | } where 154 | 155 | 156 | ∷-inj : ∀ {A a b as bs} → (Stream A _ F.∋ a ∷ as) ≡ b ∷ bs → 157 | a ≡ b × as .force ≡ bs .force 158 | ∷-inj refl = PEq.refl , refl 159 | 160 | ,-inj : {A B : Set} {a c : A} {b d : B} → (a , b) ≡ (c , d) → a ≡ c × b ≡ d 161 | ,-inj refl = PEq.refl , refl 162 | 163 | fuseRenamingPrinting : 164 | ∀ {Γ σ} (t : ε ⊢ σ) (inc : Renaming ε Γ) → 165 | print (rename inc t) 166 | ≡ proj₁ (runPrinter (printer t (Var ε ⇒[ Name ] Γ F.∋ `ε)) $ drop (size Γ) names) 167 | fuseRenamingPrinting {Γ} t inc = 168 | cong proj₁ (Fundamental.lemma fusableRenamingPrinting t (pack^R $ λ ()) $ proof Γ Γ) 169 | 170 | where 171 | 172 | tail-init : ∀ Γ Δ {ns} → tail (proj₂ (init Γ Δ ns)) ≡ proj₂ (init Γ Δ (tail ns)) 173 | tail-init ε Δ = refl 174 | tail-init (Γ ∙ _) Δ = cong tail $ tail-init Γ Δ 175 | 176 | proof : ∀ Γ Δ {names} → proj₂ (init Γ Δ names) ≡ drop (size Γ) names 177 | proof ε Δ = refl 178 | proof (Γ ∙ _) Δ {_ ∷ _} = PEq.trans (tail-init Γ Δ) (proof Γ Δ) 179 | -------------------------------------------------------------------------------- /doc/haskell/Models.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS -Wall #-} 2 | {-# LANGUAGE GADTs #-} 3 | {-# LANGUAGE EmptyCase #-} 4 | {-# LANGUAGE DataKinds #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | {-# LANGUAGE KindSignatures #-} 7 | {-# LANGUAGE RankNTypes #-} 8 | {-# LANGUAGE RecordWildCards #-} 9 | {-# LANGUAGE ScopedTypeVariables #-} 10 | 11 | module Models where 12 | 13 | import Control.Monad.State 14 | 15 | -- Types and the corresponding singleton 16 | data Ty = TyUnit | TyBool | TyFunc Ty Ty 17 | data STy :: Ty -> * where 18 | STyUnit :: STy 'TyUnit 19 | STyBool :: STy 'TyBool 20 | STyFunc :: STy a -> STy b -> STy ('TyFunc a b) 21 | 22 | -- A context is a list of types 23 | data Con = Null | Cons Con Ty 24 | data SCon :: Con -> * where 25 | SNull :: SCon 'Null 26 | SCons :: SCon g -> STy a -> SCon ('Cons g a) 27 | 28 | -- A variable is a fancy de Bruijn index 29 | data Var :: Con -> Ty -> * where 30 | Z :: Var ('Cons g a) a 31 | S :: Var g a -> Var ('Cons g b) a 32 | 33 | data Term :: Con -> Ty -> * where 34 | TeVar :: Var g a -> Term g a 35 | TeLam :: Term ('Cons g a) b -> Term g ('TyFunc a b) 36 | TeApp :: STy a -> Term g ('TyFunc a b) -> Term g a -> Term g b 37 | TeUnit :: Term g 'TyUnit 38 | TeTrue :: Term g 'TyBool 39 | TeFalse :: Term g 'TyBool 40 | TeIfte :: Term g 'TyBool -> Term g a -> Term g a -> Term g a 41 | 42 | -- An (evaluation) environment is a collection of environment 43 | -- values covering a given context `g`. 44 | 45 | type Environment (d :: Con) (e :: Con -> Ty -> *) (g :: Con) = 46 | forall a. STy a -> Var g a -> e d a 47 | 48 | envNull :: Environment d e 'Null 49 | envNull v = case v of {} 50 | 51 | envCons :: Environment d e g -> e d a -> Environment d e ('Cons g a) 52 | envCons _ e _ Z = e 53 | envCons env _ a (S v) = env a v 54 | 55 | type Included g d = Environment d Var g 56 | 57 | refl :: forall g. Included g g 58 | refl _ = id 59 | 60 | top :: forall d g a. Included g d -> Included g ('Cons d a) 61 | top inc a = S . inc a 62 | 63 | pop :: forall d g a. Included g d -> Included ('Cons g a) ('Cons d a) 64 | pop _ _ Z = Z 65 | pop inc a (S v) = S $ inc a v 66 | 67 | trans :: Included g h -> Included h i -> Included g i 68 | trans inc1 inc2 a = inc2 a . inc1 a 69 | 70 | data Semantics (e :: Con -> Ty -> *) (m :: Con -> Ty -> *) = 71 | Semantics { weak :: forall g d a. STy a -> Included g d -> e g a -> e d a 72 | , embed :: forall g a. STy a -> Var g a -> e g a 73 | , var :: forall g a. STy a -> e g a -> m g a 74 | , app :: forall g a b. STy a -> m g ('TyFunc a b) -> m g a -> m g b 75 | , lam :: forall g a b. (forall d. Included g d -> e d a -> m d b) -> m g ('TyFunc a b) 76 | , unit :: forall g. m g 'TyUnit 77 | , true :: forall g. m g 'TyBool 78 | , false :: forall g. m g 'TyBool 79 | , ifte :: forall g a. STy a -> m g 'TyBool -> m g a -> m g a -> m g a 80 | } 81 | 82 | 83 | wkEnv :: forall h d g e m. Semantics e m -> Included d h -> Environment d e g -> Environment h e g 84 | wkEnv Semantics{..} inc env a v = weak a inc $ env a v 85 | 86 | semanticsTerm :: forall e m d g a. Semantics e m -> STy a -> Term g a -> Environment d e g -> m d a 87 | semanticsTerm sem@Semantics{..} = go where 88 | go :: forall d' g' a'. STy a' -> Term g' a' -> Environment d' e g' -> m d' a' 89 | go a (TeVar v) env = var a $ env a v 90 | go (STyFunc _ b) (TeLam t) env = lam $ \ inc v -> go b t (envCons (wkEnv sem inc env) v) 91 | go b (TeApp a f t) env = app a (go (STyFunc a b) f env) (go a t env) 92 | go _ TeUnit _ = unit 93 | go _ TeTrue _ = true 94 | go _ TeFalse _ = false 95 | go a (TeIfte b l r) env = ifte a (go STyBool b env) (go a l env) (go a r env) 96 | 97 | evalTerm :: forall e m g a. Semantics e m -> SCon g -> STy a -> Term g a -> m g a 98 | evalTerm sem@Semantics{..} g a t = semanticsTerm sem a t (env g) where 99 | env :: forall g'. SCon g' -> Environment g' e g' 100 | env SNull = envNull 101 | env (SCons sg sa) = envCons (wkEnv sem (top refl) $ env sg) (embed sa Z) 102 | 103 | ------------------------------------------------------------------------ 104 | -- Syntactic Semantics 105 | ------------------------------------------------------------------------ 106 | 107 | renaming :: Semantics Var Term 108 | renaming = 109 | Semantics { weak = \ a inc v -> inc a v 110 | , embed = const id 111 | , var = const TeVar 112 | , app = TeApp 113 | , lam = \ t -> TeLam $ t (top refl) Z 114 | , unit = TeUnit 115 | , true = TeTrue 116 | , false = TeFalse 117 | , ifte = const TeIfte 118 | } 119 | 120 | weakTe :: STy a -> Included g d -> Term g a -> Term d a 121 | weakTe a inc t = semanticsTerm renaming a t inc 122 | 123 | substitution :: Semantics Term Term 124 | substitution = 125 | Semantics { weak = weakTe 126 | , embed = const TeVar 127 | , var = const id 128 | , app = TeApp 129 | , lam = \ t -> TeLam $ t (top refl) (TeVar Z) 130 | , unit = TeUnit 131 | , true = TeTrue 132 | , false = TeFalse 133 | , ifte = const TeIfte 134 | } 135 | 136 | ------------------------------------------------------------------------ 137 | -- Pretty Printing Semantics 138 | ------------------------------------------------------------------------ 139 | 140 | newtype Constant2 k (g :: Con) (s :: Ty) = Constant2 { runConstant2 :: k } 141 | 142 | prettyPrinting :: Semantics (Constant2 String) (Constant2 (State [String] String)) 143 | prettyPrinting = 144 | Semantics { weak = \ _ _ -> Constant2 . runConstant2 145 | , embed = const $ Constant2 . show . deBruijn 146 | , var = const $ Constant2 . return . runConstant2 147 | , app = \ _ mf mt -> 148 | Constant2 $ do 149 | f <- runConstant2 mf 150 | t <- runConstant2 mt 151 | return $ f ++ " (" ++ t ++ ")" 152 | , lam = \ mbody -> Constant2 $ do 153 | (x : xs) <- get 154 | () <- put xs 155 | body <- runConstant2 $ mbody (top refl) (Constant2 x) 156 | return $ '\\' : x ++ ". " ++ body 157 | , unit = Constant2 $ return "()" 158 | , true = Constant2 $ return "True" 159 | , false = Constant2 $ return "False" 160 | , ifte = \ _ mb ml mr -> 161 | Constant2 $ do 162 | b <- runConstant2 mb 163 | l <- runConstant2 ml 164 | r <- runConstant2 mr 165 | return $ "if (" ++ b ++ ") then (" ++ l ++ ") else (" ++ r ++ ")" 166 | } 167 | where 168 | deBruijn :: forall g a. Var g a -> Integer 169 | deBruijn Z = 0 170 | deBruijn (S v) = 1 + deBruijn v 171 | 172 | prettyPrint :: forall g a. SCon g -> STy a -> Term g a -> String 173 | prettyPrint g a t = evalState (runConstant2 $ evalTerm prettyPrinting g a t) names 174 | where names = fmap (:[]) alpha ++ alphaInt 175 | alpha = ['a'..'z'] 176 | alphaInt = concat $ fmap (\ i -> fmap (: show i) alpha) [(0 :: Integer)..] 177 | 178 | 179 | ------------------------------------------------------------------------ 180 | -- Normalization by Evaluation 181 | ------------------------------------------------------------------------ 182 | 183 | -- We now build a Kripke model for these terms by induction 184 | -- on the type. 185 | 186 | type family Value (g :: Con) (t :: Ty) where 187 | Value g 'TyUnit = () 188 | Value g 'TyBool = Term g 'TyBool 189 | -- And now... because polymorphic types are not allowed here 190 | -- we use `Kripke`. However newtypes are erased during compilation 191 | -- so the model definiton is indeed tagless in the end. 192 | Value g ('TyFunc a b) = Kripke g a b 193 | 194 | newtype Kripke g a b = Kripke { runKripke :: forall h. Included g h -> Value h a -> Value h b } 195 | 196 | weakValue :: forall d g a. STy a -> Included g d -> Value g a -> Value d a 197 | weakValue STyUnit _ v = v 198 | weakValue STyBool inc v = weakTe STyBool inc v 199 | weakValue (STyFunc _ _) inc v = Kripke $ \ inc' -> runKripke v (trans inc inc') 200 | 201 | reflect :: forall g a. STy a -> Term g a -> Value g a 202 | reflect STyUnit _ = () 203 | reflect STyBool t = t 204 | reflect (STyFunc a b) t = Kripke $ \ inc v -> reflect b $ TeApp a (weakTe (STyFunc a b) inc t) $ reify a v 205 | 206 | reify :: forall g a. STy a -> Value g a -> Term g a 207 | reify STyUnit _ = TeUnit 208 | reify STyBool v = v 209 | reify (STyFunc sa sb) v = TeLam $ reify sb $ body sa v where 210 | 211 | var0 :: forall c. STy c -> Value ('Cons g c) c 212 | var0 sc = reflect sc (TeVar Z :: Term ('Cons g c) c) 213 | 214 | body :: forall c d. STy c -> Kripke g c d -> Value ('Cons g c) d 215 | body sc f = runKripke f (top refl :: Included g ('Cons g c)) $ var0 sc 216 | 217 | -- Value, being a type family, cannot be partially applied. 218 | -- We introduce PValue, a newtype which can be *P*artially applied. 219 | newtype PValue (g :: Con) (a :: Ty) = PValue { runPValue :: Value g a } 220 | 221 | weakPValue :: forall d g a. STy a -> Included g d -> PValue g a -> PValue d a 222 | weakPValue a inc = PValue . weakValue a inc . runPValue 223 | 224 | normalisation :: Semantics PValue PValue 225 | normalisation = 226 | Semantics { weak = weakPValue 227 | , embed = \ sa v -> PValue $ reflect sa $ TeVar v 228 | , var = \ _ -> id 229 | , app = \ _ f t -> PValue $ runKripke (runPValue f) refl $ runPValue t 230 | , lam = \ t -> PValue $ Kripke $ \ inc -> runPValue . t inc . PValue 231 | , unit = PValue () 232 | , true = PValue TeTrue 233 | , false = PValue TeFalse 234 | , ifte = \ a b l r -> PValue $ ifte a (runPValue b) (runPValue l) (runPValue r) 235 | } where 236 | ifte :: STy a -> Value g 'TyBool -> Value g a -> Value g a -> Value g a 237 | ifte _ TeTrue l _ = l 238 | ifte _ TeFalse _ r = r 239 | ifte a b l r = reflect a $ TeIfte (reify STyBool b) (reify a l) (reify a r) 240 | 241 | normalise :: SCon g -> STy a -> Term g a -> Term g a 242 | normalise sg sa t = reify sa $ runPValue $ evalTerm normalisation sg sa t 243 | -------------------------------------------------------------------------------- /doc/main.bib: -------------------------------------------------------------------------------- 1 | @inproceedings{hatcliff1994generic, 2 | title={A generic account of continuation-passing styles}, 3 | author={Hatcliff, John and Danvy, Olivier}, 4 | booktitle={Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages}, 5 | pages={458--471}, 6 | year={1994}, 7 | organization={ACM} 8 | } 9 | @inproceedings{abel2013copatterns, 10 | title={Copatterns: programming infinite structures by observations}, 11 | author={Abel, Andreas and Pientka, Brigitte and Thibodeau, David and Setzer, Anton}, 12 | booktitle={ACM SIGPLAN Notices}, 13 | volume={48}, 14 | number={1}, 15 | pages={27--38}, 16 | year={2013}, 17 | organization={ACM} 18 | } 19 | @article{coquand1991algorithm, 20 | title={An algorithm for testing conversion in type theory}, 21 | author={Coquand, Thierry}, 22 | journal={Logical Frameworks}, 23 | volume={1}, 24 | pages={255--279}, 25 | year={1991} 26 | } 27 | @article{martin1982constructive, 28 | title={Constructive mathematics and computer programming}, 29 | author={Martin-L{\"o}f, Per}, 30 | journal={Studies in Logic and the Foundations of Mathematics}, 31 | volume={104}, 32 | pages={153--175}, 33 | year={1982}, 34 | publisher={Elsevier} 35 | } 36 | @inproceedings{atkey2009syntax, 37 | title={Syntax for free: Representing syntax with binding using parametricity}, 38 | author={Atkey, Robert}, 39 | booktitle={TLCA}, 40 | pages={35--49}, 41 | year={2009}, 42 | organization={Springer} 43 | } 44 | @article{carette2009finally, 45 | title={Finally tagless, partially evaluated}, 46 | author={Carette, Jacques and Kiselyov, Oleg and Shan, Chung-chieh}, 47 | journal={JFP}, 48 | year={2009}, 49 | publisher={Citeseer} 50 | } 51 | @article{abel2014normalization, 52 | title={Normalization by evaluation in the delay monad}, 53 | author={Abel, Andreas and Chapman, James}, 54 | journal={MSFP 2014}, 55 | year={2014} 56 | } 57 | @incollection{hughes1995design, 58 | title={The design of a pretty-printing library}, 59 | author={Hughes, John}, 60 | booktitle={AFP Summer School}, 61 | pages={53--96}, 62 | year={1995}, 63 | publisher={Springer} 64 | } 65 | @phdthesis{chapman2009type, 66 | title={Type checking and normalisation}, 67 | author={Chapman, James Maitland}, 68 | year={2009}, 69 | school={University of Nottingham} 70 | } 71 | @article{girard1972interpretation, 72 | title={Interpr{\'e}tation fonctionelle et {\'e}limination des coupures de l’arithm{\'e}tique d’ordre sup{\'e}rieur}, 73 | author={Girard, Jean-Yves}, 74 | year={1972}, 75 | publisher={PhD thesis, Universit{\'e} Paris VII} 76 | } 77 | @article{wadler1990deforestation, 78 | title={Deforestation: Transforming programs to eliminate trees}, 79 | author={Wadler, Philip}, 80 | journal={TCS}, 81 | volume={73}, 82 | number={2}, 83 | pages={231--248}, 84 | year={1990}, 85 | publisher={Elsevier} 86 | } 87 | @article{wadler2003prettier, 88 | title={A prettier printer}, 89 | author={Wadler, Philip}, 90 | journal={The Fun of Programming, Cornerstones of Computing}, 91 | pages={223--243}, 92 | year={2003}, 93 | publisher={Citeseer} 94 | } 95 | @inproceedings{chlipala2008parametric, 96 | title={Parametric higher-order abstract syntax for mechanized semantics}, 97 | author={Chlipala, Adam}, 98 | booktitle={ACM Sigplan Notices}, 99 | volume={43}, 100 | number={9}, 101 | pages={143--156}, 102 | year={2008}, 103 | organization={ACM} 104 | } 105 | @misc{jeffrey2011assoc, 106 | title={Associativity for free!}, 107 | author={Jeffrey, Alan}, 108 | howpublished={\url{http://thread.gmane.org/gmane.comp.lang.agda/3259}}, 109 | year={2011}, 110 | publisher={Agda Mailing List} 111 | } 112 | @article{goguen1997candidates, 113 | title={Candidates for substitution}, 114 | author={Goguen, Healfdene and McKinna, James}, 115 | journal={LFCS, Edinburgh Techreport}, 116 | year={1997}, 117 | publisher={UNIVERSITY OF EDINBURGH} 118 | } 119 | @article{gill2014domain, 120 | title={Domain-specific languages and code synthesis using {H}askell}, 121 | author={Gill, Andy}, 122 | journal={Queue}, 123 | volume={12}, 124 | number={4}, 125 | pages={30}, 126 | year={2014}, 127 | publisher={ACM} 128 | } 129 | @incollection{svenningsson2013combining, 130 | title={Combining deep and shallow embedding for {EDSL}}, 131 | author={Svenningsson, Josef and Axelsson, Emil}, 132 | booktitle={TFP}, 133 | pages={21--36}, 134 | year={2013}, 135 | publisher={Springer} 136 | } 137 | @article{hudak1996building, 138 | title={Building domain-specific embedded languages}, 139 | author={Hudak, Paul}, 140 | journal={ACM Computing Surveys (CSUR)}, 141 | volume={28}, 142 | number={4es}, 143 | pages={196}, 144 | year={1996}, 145 | publisher={ACM} 146 | } 147 | @incollection{berger1993program, 148 | title={Program extraction from normalization proofs}, 149 | author={Berger, Ulrich}, 150 | booktitle={TLCA}, 151 | pages={91--106}, 152 | year={1993}, 153 | publisher={Springer} 154 | } 155 | @article{CoqDybSK, 156 | title={Intuitionistic model constructions and normalization proofs}, 157 | author={Coquand, Thierry and Dybjer, Peter}, 158 | journal={MSCS}, 159 | volume={7}, 160 | number={01}, 161 | pages={75--94}, 162 | year={1997}, 163 | publisher={Cambridge Univ. Press} 164 | } 165 | @Manual{Coq:manual, 166 | title = {The Coq proof assistant reference manual}, 167 | author = {\mbox{The Coq development team}}, 168 | note = {Version 8.0}, 169 | year = {2004}, 170 | url = "http://coq.inria.fr" 171 | } 172 | @article{lindley2014hasochism, 173 | title={Hasochism}, 174 | author={Lindley, Sam and McBride, Conor}, 175 | journal={SIGPLAN Notices}, 176 | volume={48}, 177 | number={12}, 178 | pages={81--92}, 179 | year={2014}, 180 | publisher={ACM} 181 | } 182 | @article{mcbride2004view, 183 | title={The view from the left}, 184 | author={McBride, Conor and McKinna, James}, 185 | journal={JFP}, 186 | volume={14}, 187 | number={01}, 188 | pages={69--111}, 189 | year={2004}, 190 | publisher={Cambridge Univ. Press} 191 | } 192 | @book{mitchell1996foundations, 193 | title={Foundations for programming languages}, 194 | author={Mitchell, John C}, 195 | volume={1}, 196 | year={1996}, 197 | publisher={MIT press} 198 | } 199 | @inproceedings{de1972lambda, 200 | title={Lambda {C}alculus Notation with Nameless Dummies}, 201 | author={de Bruijn, Nicolaas Govert}, 202 | booktitle={Indagationes Mathematicae}, 203 | volume={75}, 204 | number={5}, 205 | pages={381--392}, 206 | year={1972}, 207 | organization={Elsevier} 208 | } 209 | @inproceedings{altenkirch1995categorical, 210 | title={Categorical reconstruction of a reduction free normalization proof}, 211 | author={Altenkirch, Thorsten and Hofmann, Martin and Streicher, Thomas}, 212 | booktitle={LNCS}, 213 | pages={182--199}, 214 | year={1995}, 215 | volume={530}, 216 | organization={Springer} 217 | } 218 | @article{mitchell1991kripke, 219 | title={Kripke-style models for typed lambda calculus}, 220 | author={Mitchell, John C and Moggi, Eugenio}, 221 | journal={Annals of Pure and Applied Logic}, 222 | volume={51}, 223 | number={1}, 224 | pages={99--124}, 225 | year={1991}, 226 | publisher={Elsevier} 227 | } 228 | @inproceedings{altenkirch1999monadic, 229 | title={Monadic presentations of lambda terms using generalized inductive types}, 230 | author={Altenkirch, Thorsten and Reus, Bernhard}, 231 | booktitle={CSL}, 232 | pages={453--468}, 233 | year={1999}, 234 | organization={Springer} 235 | } 236 | @article{dybjer1991inductive, 237 | title={Inductive sets and families in {M}artin-{L}{\"o}f’s type theory and their set-theoretic semantics}, 238 | author={Dybjer, Peter}, 239 | journal={Logical Frameworks}, 240 | volume={2}, 241 | pages={6}, 242 | year={1991} 243 | } 244 | @article{eisenberg2013dependently, 245 | title={Dependently typed programming with singletons}, 246 | author={Eisenberg, Richard A and Weirich, Stephanie}, 247 | journal={SIGPLAN Notices}, 248 | volume={47}, 249 | number={12}, 250 | pages={117--130}, 251 | year={2013}, 252 | publisher={ACM} 253 | } 254 | @incollection{norell2009dependently, 255 | title={Dependently typed programming in {A}gda}, 256 | author={Norell, Ulf}, 257 | booktitle={AFP Summer School}, 258 | pages={230--266}, 259 | year={2009}, 260 | publisher={Springer} 261 | } 262 | @unpublished{danvytagless, 263 | title={Tagless and Typeful Normalization by Evaluation using Generalized Algebraic Data Types}, 264 | author={Danvy, Olivier and Keller, Chantal and Puech, Matthias}, 265 | year={2013} 266 | } 267 | @article{reynolds1983types, 268 | title={Types, abstraction and parametric polymorphism}, 269 | author={Reynolds, John C}, 270 | year={1983} 271 | } 272 | @article{bernardy2013type, 273 | title={Type-theory in color}, 274 | author={Bernardy, Jean-Philippe and Moulin, Guilhem}, 275 | journal={SIGPLAN Notices}, 276 | volume={48}, 277 | number={9}, 278 | pages={61--72}, 279 | year={2013}, 280 | publisher={ACM} 281 | } 282 | @article{wiedijk2012pollack, 283 | title={Pollack-inconsistency}, 284 | author={Wiedijk, Freek}, 285 | journal={ENTCS}, 286 | volume={285}, 287 | pages={85--100}, 288 | year={2012}, 289 | publisher={Elsevier} 290 | } 291 | @incollection{danvy1999type, 292 | title={Type-directed partial evaluation}, 293 | author={Danvy, Olivier}, 294 | booktitle={Partial Evaluation}, 295 | pages={367--411}, 296 | year={1999}, 297 | publisher={Springer} 298 | } 299 | @inproceedings{berger1991inverse, 300 | title={An inverse of the evaluation functional for typed $\lambda$-calculus}, 301 | author={Berger, Ulrich and Schwichtenberg, Helmut}, 302 | booktitle={LICS}, 303 | pages={203--211}, 304 | year={1991}, 305 | organization={IEEE} 306 | } 307 | @article{coquand2002formalised, 308 | title={A formalised proof of the soundness and completeness of a simply typed lambda-calculus with explicit substitutions}, 309 | author={Coquand, Catarina}, 310 | journal={Higher-Order and Symbolic Computation}, 311 | volume={15}, 312 | number={1}, 313 | pages={57--90}, 314 | year={2002}, 315 | publisher={Springer} 316 | } 317 | @article{benton2012strongly, 318 | title={Strongly typed term representations in {C}oq}, 319 | author={Benton, Nick and Hur, Chung-Kil and Kennedy, Andrew J and McBride, Conor}, 320 | journal={JAR}, 321 | volume={49}, 322 | number={2}, 323 | pages={141--159}, 324 | year={2012}, 325 | publisher={Springer} 326 | } 327 | @article{mcbride2005type, 328 | title={Type-preserving renaming and substitution}, 329 | author={McBride, Conor}, 330 | year={2005}, 331 | publisher={Citeseer} 332 | } 333 | @incollection{garillot2009packaging, 334 | title={Packaging mathematical structures}, 335 | author={Garillot, Fran{\c{c}}ois and Gonthier, Georges and Mahboubi, Assia and Rideau, Laurence}, 336 | booktitle={TPHOLs}, 337 | pages={327--342}, 338 | year={2009}, 339 | publisher={Springer} 340 | } 341 | @incollection{danielsson2011parsing, 342 | title={Parsing mixfix operators}, 343 | author={Danielsson, Nils Anders and Norell, Ulf}, 344 | booktitle={IFL}, 345 | pages={80--99}, 346 | year={2011}, 347 | publisher={Springer} 348 | } 349 | @article{moggi1991notions, 350 | title={Notions of computation and monads}, 351 | author={Moggi, Eugenio}, 352 | journal={Information and Computation}, 353 | volume={93}, 354 | number={1}, 355 | pages={55--92}, 356 | year={1991}, 357 | publisher={Elsevier} 358 | } 359 | 360 | @misc{repo, 361 | author = {Guillaume Allais and James Chapman and Conor McBride and James McKinna}, 362 | title = {Type-and-Scope Safe Programs and Their Proofs -- Agda Formalization}, 363 | doi = {10.15129}, 364 | howpublished = {\url{http://dx.doi.org/10.15129/f1283dbb-64fd-4d35-aacc-49d3cc0893b8}}, 365 | note = {Also from github \url{https://github.com/gallais/type-scope-semantics}}} -------------------------------------------------------------------------------- /doc/sigplanconf.cls: -------------------------------------------------------------------------------- 1 | %----------------------------------------------------------------------------- 2 | % 3 | % LaTeX Class/Style File 4 | % 5 | % Name: sigplanconf.cls 6 | % 7 | % Purpose: A LaTeX 2e class file for SIGPLAN conference proceedings. 8 | % This class file supercedes acm_proc_article-sp, 9 | % sig-alternate, and sigplan-proc. 10 | % 11 | % Author: Paul C. Anagnostopoulos 12 | % Windfall Software 13 | % 978 371-2316 14 | % paul [atsign] windfall.com 15 | % 16 | % Created: 12 September 2004 17 | % 18 | % Revisions: See end of file. 19 | % 20 | % This work is licensed under the Creative Commons Attribution License. 21 | % To view a copy of this license, visit 22 | % http://creativecommons.org/licenses/by/3.0/ 23 | % or send a letter to Creative Commons, 171 2nd Street, Suite 300, 24 | % San Francisco, California, 94105, U.S.A. 25 | % 26 | % Program Chairs may be tempted to make changes to the SIGPLAN LaTeX style 27 | % sigplanconf.cls. Please don't do this! The style is carefully considered, 28 | % and the result of over a decade's discussion and development. If you have a 29 | % change request, send it to the SIGPLAN Information Director 30 | % infodir_sigplan@acm.org. If you absolutely must change the formatting, 31 | % define a new class file (eg myconf1999.cls) that imports sigplanconf.cls, or 32 | % define a style file (eg myconf1999.sty) for authors to use in their papers. 33 | % Contact the Information Director for details and examples. Please, UNDER NO 34 | % CIRCUMSTANCES should you modify the file sigplanconf.cls and release it onto 35 | % the internet---that way lies madness for future conferences! 36 | % 37 | %----------------------------------------------------------------------------- 38 | 39 | 40 | \NeedsTeXFormat{LaTeX2e}[1995/12/01] 41 | \ProvidesClass{sigplanconf}[2015/12/03 v3.2 ACM SIGPLAN Proceedings] 42 | 43 | % The following few pages contain LaTeX programming extensions adapted 44 | % from the ZzTeX macro package. 45 | 46 | % Token Hackery 47 | % ----- ------- 48 | 49 | 50 | \def \@expandaftertwice {\expandafter\expandafter\expandafter} 51 | \def \@expandafterthrice {\expandafter\expandafter\expandafter\expandafter 52 | \expandafter\expandafter\expandafter} 53 | 54 | % This macro discards the next token. 55 | 56 | \def \@discardtok #1{}% token 57 | 58 | % This macro removes the `pt' following a dimension. 59 | 60 | {\catcode `\p = 12 \catcode `\t = 12 61 | 62 | \gdef \@remover #1pt{#1} 63 | 64 | } % \catcode 65 | 66 | % This macro extracts the contents of a macro and returns it as plain text. 67 | % Usage: \expandafter\@defof \meaning\macro\@mark 68 | 69 | \def \@defof #1:->#2\@mark{#2} 70 | 71 | % Control Sequence Names 72 | % ------- -------- ----- 73 | 74 | 75 | \def \@name #1{% {\tokens} 76 | \csname \expandafter\@discardtok \string#1\endcsname} 77 | 78 | \def \@withname #1#2{% {\command}{\tokens} 79 | \expandafter#1\csname \expandafter\@discardtok \string#2\endcsname} 80 | 81 | % Flags (Booleans) 82 | % ----- ---------- 83 | 84 | % The boolean literals \@true and \@false are appropriate for use with 85 | % the \if command, which tests the codes of the next two characters. 86 | 87 | \def \@true {TT} 88 | \def \@false {FL} 89 | 90 | \def \@setflag #1=#2{\edef #1{#2}}% \flag = boolean 91 | 92 | % IF and Predicates 93 | % -- --- ---------- 94 | 95 | % A "predicate" is a macro that returns \@true or \@false as its value. 96 | % Such values are suitable for use with the \if conditional. For example: 97 | % 98 | % \if \@oddp{\x} \else \fi 99 | 100 | % A predicate can be used with \@setflag as follows: 101 | % 102 | % \@setflag \flag = {} 103 | 104 | % Here are the predicates for TeX's repertoire of conditional 105 | % commands. These might be more appropriately interspersed with 106 | % other definitions in this module, but what the heck. 107 | % Some additional "obvious" predicates are defined. 108 | 109 | \def \@eqlp #1#2{\ifnum #1 = #2\@true \else \@false \fi} 110 | \def \@neqlp #1#2{\ifnum #1 = #2\@false \else \@true \fi} 111 | \def \@lssp #1#2{\ifnum #1 < #2\@true \else \@false \fi} 112 | \def \@gtrp #1#2{\ifnum #1 > #2\@true \else \@false \fi} 113 | \def \@zerop #1{\ifnum #1 = 0\@true \else \@false \fi} 114 | \def \@onep #1{\ifnum #1 = 1\@true \else \@false \fi} 115 | \def \@posp #1{\ifnum #1 > 0\@true \else \@false \fi} 116 | \def \@negp #1{\ifnum #1 < 0\@true \else \@false \fi} 117 | \def \@oddp #1{\ifodd #1\@true \else \@false \fi} 118 | \def \@evenp #1{\ifodd #1\@false \else \@true \fi} 119 | \def \@rangep #1#2#3{\if \@orp{\@lssp{#1}{#2}}{\@gtrp{#1}{#3}}\@false \else 120 | \@true \fi} 121 | \def \@tensp #1{\@rangep{#1}{10}{19}} 122 | 123 | \def \@dimeqlp #1#2{\ifdim #1 = #2\@true \else \@false \fi} 124 | \def \@dimneqlp #1#2{\ifdim #1 = #2\@false \else \@true \fi} 125 | \def \@dimlssp #1#2{\ifdim #1 < #2\@true \else \@false \fi} 126 | \def \@dimgtrp #1#2{\ifdim #1 > #2\@true \else \@false \fi} 127 | \def \@dimzerop #1{\ifdim #1 = 0pt\@true \else \@false \fi} 128 | \def \@dimposp #1{\ifdim #1 > 0pt\@true \else \@false \fi} 129 | \def \@dimnegp #1{\ifdim #1 < 0pt\@true \else \@false \fi} 130 | 131 | \def \@vmodep {\ifvmode \@true \else \@false \fi} 132 | \def \@hmodep {\ifhmode \@true \else \@false \fi} 133 | \def \@mathmodep {\ifmmode \@true \else \@false \fi} 134 | \def \@textmodep {\ifmmode \@false \else \@true \fi} 135 | \def \@innermodep {\ifinner \@true \else \@false \fi} 136 | 137 | \long\def \@codeeqlp #1#2{\if #1#2\@true \else \@false \fi} 138 | 139 | \long\def \@cateqlp #1#2{\ifcat #1#2\@true \else \@false \fi} 140 | 141 | \long\def \@tokeqlp #1#2{\ifx #1#2\@true \else \@false \fi} 142 | \long\def \@xtokeqlp #1#2{\expandafter\ifx #1#2\@true \else \@false \fi} 143 | 144 | \long\def \@definedp #1{% 145 | \expandafter\ifx \csname \expandafter\@discardtok \string#1\endcsname 146 | \relax \@false \else \@true \fi} 147 | 148 | \long\def \@undefinedp #1{% 149 | \expandafter\ifx \csname \expandafter\@discardtok \string#1\endcsname 150 | \relax \@true \else \@false \fi} 151 | 152 | \def \@emptydefp #1{\ifx #1\@empty \@true \else \@false \fi}% {\name} 153 | 154 | \let \@emptylistp = \@emptydefp 155 | 156 | \long\def \@emptyargp #1{% {#n} 157 | \@empargp #1\@empargq\@mark} 158 | \long\def \@empargp #1#2\@mark{% 159 | \ifx #1\@empargq \@true \else \@false \fi} 160 | \def \@empargq {\@empargq} 161 | 162 | \def \@emptytoksp #1{% {\tokenreg} 163 | \expandafter\@emptoksp \the#1\@mark} 164 | 165 | \long\def \@emptoksp #1\@mark{\@emptyargp{#1}} 166 | 167 | \def \@voidboxp #1{\ifvoid #1\@true \else \@false \fi} 168 | \def \@hboxp #1{\ifhbox #1\@true \else \@false \fi} 169 | \def \@vboxp #1{\ifvbox #1\@true \else \@false \fi} 170 | 171 | \def \@eofp #1{\ifeof #1\@true \else \@false \fi} 172 | 173 | 174 | % Flags can also be used as predicates, as in: 175 | % 176 | % \if \flaga \else \fi 177 | 178 | 179 | % Now here we have predicates for the common logical operators. 180 | 181 | \def \@notp #1{\if #1\@false \else \@true \fi} 182 | 183 | \def \@andp #1#2{\if #1% 184 | \if #2\@true \else \@false \fi 185 | \else 186 | \@false 187 | \fi} 188 | 189 | \def \@orp #1#2{\if #1% 190 | \@true 191 | \else 192 | \if #2\@true \else \@false \fi 193 | \fi} 194 | 195 | \def \@xorp #1#2{\if #1% 196 | \if #2\@false \else \@true \fi 197 | \else 198 | \if #2\@true \else \@false \fi 199 | \fi} 200 | 201 | % Arithmetic 202 | % ---------- 203 | 204 | \def \@increment #1{\advance #1 by 1\relax}% {\count} 205 | 206 | \def \@decrement #1{\advance #1 by -1\relax}% {\count} 207 | 208 | % Options 209 | % ------- 210 | 211 | 212 | \@setflag \@authoryear = \@true 213 | \@setflag \@blockstyle = \@false 214 | \@setflag \@copyrightwanted = \@true 215 | \@setflag \@explicitsize = \@false 216 | \@setflag \@legacycopyright = \@false 217 | \@setflag \@mathtime = \@false 218 | \@setflag \@natbib = \@true 219 | \@setflag \@ninepoint = \@true 220 | \newcount{\@numheaddepth} \@numheaddepth = 3 221 | \@setflag \@onecolumn = \@false 222 | \@setflag \@preprint = \@false 223 | \@setflag \@reprint = \@false 224 | \@setflag \@tenpoint = \@false 225 | \@setflag \@times = \@false 226 | 227 | % Note that all the dangerous article class options are trapped. 228 | 229 | \DeclareOption{9pt}{\@setflag \@ninepoint = \@true 230 | \@setflag \@explicitsize = \@true} 231 | 232 | \DeclareOption{10pt}{\PassOptionsToClass{10pt}{article}% 233 | \@setflag \@ninepoint = \@false 234 | \@setflag \@tenpoint = \@true 235 | \@setflag \@explicitsize = \@true} 236 | 237 | \DeclareOption{11pt}{\PassOptionsToClass{11pt}{article}% 238 | \@setflag \@ninepoint = \@false 239 | \@setflag \@explicitsize = \@true} 240 | 241 | \DeclareOption{12pt}{\@unsupportedoption{12pt}} 242 | 243 | \DeclareOption{a4paper}{\@unsupportedoption{a4paper}} 244 | 245 | \DeclareOption{a5paper}{\@unsupportedoption{a5paper}} 246 | 247 | \DeclareOption{authoryear}{\@setflag \@authoryear = \@true} 248 | 249 | \DeclareOption{b5paper}{\@unsupportedoption{b5paper}} 250 | 251 | \DeclareOption{blockstyle}{\@setflag \@blockstyle = \@true} 252 | 253 | \DeclareOption{cm}{\@setflag \@times = \@false} 254 | 255 | \DeclareOption{computermodern}{\@setflag \@times = \@false} 256 | 257 | \DeclareOption{executivepaper}{\@unsupportedoption{executivepaper}} 258 | 259 | \DeclareOption{indentedstyle}{\@setflag \@blockstyle = \@false} 260 | 261 | \DeclareOption{landscape}{\@unsupportedoption{landscape}} 262 | 263 | \DeclareOption{legacycopyright}{\@setflag \@legacycopyright = \@true} 264 | 265 | \DeclareOption{legalpaper}{\@unsupportedoption{legalpaper}} 266 | 267 | \DeclareOption{letterpaper}{\@unsupportedoption{letterpaper}} 268 | 269 | \DeclareOption{mathtime}{\@setflag \@mathtime = \@true} 270 | 271 | \DeclareOption{natbib}{\@setflag \@natbib = \@true} 272 | 273 | \DeclareOption{nonatbib}{\@setflag \@natbib = \@false} 274 | 275 | \DeclareOption{nocopyrightspace}{\@setflag \@copyrightwanted = \@false} 276 | 277 | \DeclareOption{notitlepage}{\@unsupportedoption{notitlepage}} 278 | 279 | \DeclareOption{numberedpars}{\@numheaddepth = 4} 280 | 281 | \DeclareOption{numbers}{\@setflag \@authoryear = \@false} 282 | 283 | %%%\DeclareOption{onecolumn}{\@setflag \@onecolumn = \@true} 284 | 285 | \DeclareOption{preprint}{\@setflag \@preprint = \@true} 286 | 287 | \DeclareOption{reprint}{\@setflag \@reprint = \@true} 288 | 289 | \DeclareOption{times}{\@setflag \@times = \@true} 290 | 291 | \DeclareOption{titlepage}{\@unsupportedoption{titlepage}} 292 | 293 | \DeclareOption{twocolumn}{\@setflag \@onecolumn = \@false} 294 | 295 | \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} 296 | 297 | \ExecuteOptions{9pt,indentedstyle,times} 298 | \@setflag \@explicitsize = \@false 299 | \ProcessOptions 300 | 301 | \if \@onecolumn 302 | \if \@notp{\@explicitsize}% 303 | \@setflag \@ninepoint = \@false 304 | \PassOptionsToClass{11pt}{article}% 305 | \fi 306 | \PassOptionsToClass{twoside,onecolumn}{article} 307 | \else 308 | \PassOptionsToClass{twoside,twocolumn}{article} 309 | \fi 310 | \LoadClass{article} 311 | 312 | \def \@unsupportedoption #1{% 313 | \ClassError{proc}{The standard '#1' option is not supported.}} 314 | 315 | % This can be used with the 'reprint' option to get the final folios. 316 | 317 | \def \setpagenumber #1{% 318 | \setcounter{page}{#1}} 319 | 320 | \AtEndDocument{\label{sigplanconf@finalpage}} 321 | 322 | % Utilities 323 | % --------- 324 | 325 | 326 | \newcommand{\setvspace}[2]{% 327 | #1 = #2 328 | \advance #1 by -1\parskip} 329 | 330 | % Document Parameters 331 | % -------- ---------- 332 | 333 | 334 | % Page: 335 | 336 | \setlength{\hoffset}{-1in} 337 | \setlength{\voffset}{-1in} 338 | 339 | \setlength{\topmargin}{1in} 340 | \setlength{\headheight}{0pt} 341 | \setlength{\headsep}{0pt} 342 | 343 | \if \@onecolumn 344 | \setlength{\evensidemargin}{.75in} 345 | \setlength{\oddsidemargin}{.75in} 346 | \else 347 | \setlength{\evensidemargin}{.75in} 348 | \setlength{\oddsidemargin}{.75in} 349 | \fi 350 | 351 | % Text area: 352 | 353 | \newdimen{\standardtextwidth} 354 | \setlength{\standardtextwidth}{42pc} 355 | 356 | \if \@onecolumn 357 | \setlength{\textwidth}{40.5pc} 358 | \else 359 | \setlength{\textwidth}{\standardtextwidth} 360 | \fi 361 | 362 | \setlength{\topskip}{8pt} 363 | \setlength{\columnsep}{2pc} 364 | \setlength{\textheight}{54.5pc} 365 | 366 | % Running foot: 367 | 368 | \setlength{\footskip}{30pt} 369 | 370 | % Paragraphs: 371 | 372 | \if \@blockstyle 373 | \setlength{\parskip}{5pt plus .1pt minus .5pt} 374 | \setlength{\parindent}{0pt} 375 | \else 376 | \setlength{\parskip}{0pt} 377 | \setlength{\parindent}{12pt} 378 | \fi 379 | 380 | \setlength{\lineskip}{.5pt} 381 | \setlength{\lineskiplimit}{\lineskip} 382 | 383 | \frenchspacing 384 | \pretolerance = 400 385 | \tolerance = \pretolerance 386 | \setlength{\emergencystretch}{5pt} 387 | \clubpenalty = 10000 388 | \widowpenalty = 10000 389 | \setlength{\hfuzz}{.5pt} 390 | 391 | % Standard vertical spaces: 392 | 393 | \newskip{\standardvspace} 394 | \setvspace{\standardvspace}{5pt plus 1pt minus .5pt} 395 | 396 | % Margin paragraphs: 397 | 398 | \setlength{\marginparwidth}{36pt} 399 | \setlength{\marginparsep}{2pt} 400 | \setlength{\marginparpush}{8pt} 401 | 402 | 403 | \setlength{\skip\footins}{8pt plus 3pt minus 1pt} 404 | \setlength{\footnotesep}{9pt} 405 | 406 | \renewcommand{\footnoterule}{% 407 | \hrule width .5\columnwidth height .33pt depth 0pt} 408 | 409 | \renewcommand{\@makefntext}[1]{% 410 | \noindent \@makefnmark \hspace{1pt}#1} 411 | 412 | % Floats: 413 | 414 | \setcounter{topnumber}{4} 415 | \setcounter{bottomnumber}{1} 416 | \setcounter{totalnumber}{4} 417 | 418 | \renewcommand{\fps@figure}{tp} 419 | \renewcommand{\fps@table}{tp} 420 | \renewcommand{\topfraction}{0.90} 421 | \renewcommand{\bottomfraction}{0.30} 422 | \renewcommand{\textfraction}{0.10} 423 | \renewcommand{\floatpagefraction}{0.75} 424 | 425 | \setcounter{dbltopnumber}{4} 426 | 427 | \renewcommand{\dbltopfraction}{\topfraction} 428 | \renewcommand{\dblfloatpagefraction}{\floatpagefraction} 429 | 430 | \setlength{\floatsep}{18pt plus 4pt minus 2pt} 431 | \setlength{\textfloatsep}{18pt plus 4pt minus 3pt} 432 | \setlength{\intextsep}{10pt plus 4pt minus 3pt} 433 | 434 | \setlength{\dblfloatsep}{18pt plus 4pt minus 2pt} 435 | \setlength{\dbltextfloatsep}{20pt plus 4pt minus 3pt} 436 | 437 | % Miscellaneous: 438 | 439 | \errorcontextlines = 5 440 | 441 | % Fonts 442 | % ----- 443 | 444 | 445 | \if \@times 446 | \renewcommand{\rmdefault}{ptm}% 447 | \if \@mathtime 448 | \usepackage[mtbold,noTS1]{mathtime}% 449 | \else 450 | %%% \usepackage{mathptmx}% 451 | \fi 452 | \else 453 | \relax 454 | \fi 455 | 456 | \if \@ninepoint 457 | 458 | \renewcommand{\normalsize}{% 459 | \@setfontsize{\normalsize}{9pt}{10pt}% 460 | \setlength{\abovedisplayskip}{5pt plus 1pt minus .5pt}% 461 | \setlength{\belowdisplayskip}{\abovedisplayskip}% 462 | \setlength{\abovedisplayshortskip}{3pt plus 1pt minus 2pt}% 463 | \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} 464 | 465 | \renewcommand{\tiny}{\@setfontsize{\tiny}{5pt}{6pt}} 466 | 467 | \renewcommand{\scriptsize}{\@setfontsize{\scriptsize}{7pt}{8pt}} 468 | 469 | \renewcommand{\small}{% 470 | \@setfontsize{\small}{8pt}{9pt}% 471 | \setlength{\abovedisplayskip}{4pt plus 1pt minus 1pt}% 472 | \setlength{\belowdisplayskip}{\abovedisplayskip}% 473 | \setlength{\abovedisplayshortskip}{2pt plus 1pt}% 474 | \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} 475 | 476 | \renewcommand{\footnotesize}{% 477 | \@setfontsize{\footnotesize}{8pt}{9pt}% 478 | \setlength{\abovedisplayskip}{4pt plus 1pt minus .5pt}% 479 | \setlength{\belowdisplayskip}{\abovedisplayskip}% 480 | \setlength{\abovedisplayshortskip}{2pt plus 1pt}% 481 | \setlength{\belowdisplayshortskip}{\abovedisplayshortskip}} 482 | 483 | \renewcommand{\large}{\@setfontsize{\large}{11pt}{13pt}} 484 | 485 | \renewcommand{\Large}{\@setfontsize{\Large}{14pt}{18pt}} 486 | 487 | \renewcommand{\LARGE}{\@setfontsize{\LARGE}{18pt}{20pt}} 488 | 489 | \renewcommand{\huge}{\@setfontsize{\huge}{20pt}{25pt}} 490 | 491 | \renewcommand{\Huge}{\@setfontsize{\Huge}{25pt}{30pt}} 492 | 493 | \else\if \@tenpoint 494 | 495 | \relax 496 | 497 | \else 498 | 499 | \relax 500 | 501 | \fi\fi 502 | 503 | % Abstract 504 | % -------- 505 | 506 | 507 | \renewenvironment{abstract}{% 508 | \section*{Abstract}% 509 | \normalsize}{% 510 | } 511 | 512 | % Bibliography 513 | % ------------ 514 | 515 | 516 | \renewenvironment{thebibliography}[1] 517 | {\section*{\refname 518 | \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}}% 519 | \list{\@biblabel{\@arabic\c@enumiv}}% 520 | {\settowidth\labelwidth{\@biblabel{#1}}% 521 | \leftmargin\labelwidth 522 | \advance\leftmargin\labelsep 523 | \@openbib@code 524 | \usecounter{enumiv}% 525 | \let\p@enumiv\@empty 526 | \renewcommand\theenumiv{\@arabic\c@enumiv}}% 527 | \bibfont 528 | \clubpenalty4000 529 | \@clubpenalty \clubpenalty 530 | \widowpenalty4000% 531 | \sfcode`\.\@m} 532 | {\def\@noitemerr 533 | {\@latex@warning{Empty `thebibliography' environment}}% 534 | \endlist} 535 | 536 | \if \@natbib 537 | 538 | \if \@authoryear 539 | \typeout{Using natbib package with 'authoryear' citation style.} 540 | \usepackage[authoryear,square]{natbib} 541 | \bibpunct{(}{)}{;}{a}{}{,} % Change fences to parentheses; 542 | % citation separator to semicolon; 543 | % eliminate comma between author and year. 544 | \let \cite = \citep 545 | \else 546 | \typeout{Using natbib package with 'numbers' citation style.} 547 | \usepackage[numbers,sort&compress,square]{natbib} 548 | \fi 549 | \setlength{\bibsep}{3pt plus .5pt minus .25pt} 550 | 551 | \fi 552 | 553 | \def \bibfont {\small} 554 | 555 | % Categories 556 | % ---------- 557 | 558 | 559 | \@setflag \@firstcategory = \@true 560 | 561 | \newcommand{\category}[3]{% 562 | \if \@firstcategory 563 | \paragraph*{Categories and Subject Descriptors}% 564 | \@setflag \@firstcategory = \@false 565 | \else 566 | \unskip ;\hspace{.75em}% 567 | \fi 568 | \@ifnextchar [{\@category{#1}{#2}{#3}}{\@category{#1}{#2}{#3}[]}} 569 | 570 | \def \@category #1#2#3[#4]{% 571 | {\let \and = \relax 572 | #1 [\textit{#2}]% 573 | \if \@emptyargp{#4}% 574 | \if \@notp{\@emptyargp{#3}}: #3\fi 575 | \else 576 | :\space 577 | \if \@notp{\@emptyargp{#3}}#3---\fi 578 | \textrm{#4}% 579 | \fi}} 580 | 581 | % Copyright Notice 582 | % --------- ------ 583 | 584 | 585 | \def \ftype@copyrightbox {8} 586 | \def \@toappear {} 587 | \def \@permission {} 588 | \def \@reprintprice {} 589 | 590 | \def \@copyrightspace {% 591 | \@float{copyrightbox}[b]% 592 | \vbox to 1in{% 593 | \vfill 594 | \parbox[b]{20pc}{% 595 | \tiny 596 | \if \@preprint 597 | [Copyright notice will appear here 598 | once 'preprint' option is removed.]\par 599 | \else 600 | \@toappear 601 | \fi 602 | \if \@reprint 603 | \noindent Reprinted from \@conferencename, 604 | \@proceedings, 605 | \@conferenceinfo, 606 | pp.~\number\thepage--\pageref{sigplanconf@finalpage}.\par 607 | \fi}}% 608 | \end@float} 609 | 610 | \long\def \toappear #1{% 611 | \def \@toappear {#1}} 612 | 613 | \toappear{% 614 | \if \@andp{\@legacycopyright}{\@emptydefp{\@permission}}% 615 | \noindent (No legacy permission statement was specified.)\par 616 | \else 617 | \noindent \@permission \par 618 | \fi 619 | \vspace{2pt} 620 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 621 | \noindent Copyright \copyright\ \@copyrightyear\ ACM \@copyrightdata 622 | \dots \@reprintprice\par 623 | \setcopyrightdoi} 624 | 625 | \def \publicationrights #1{% {type} 626 | \if \@definedp{\rightsstatement#1}% 627 | \gdef \@toappear {\@name{\rightsstatement#1}}% 628 | \else 629 | \@latex@error{The publication right '#1' is invalid}{}% 630 | \fi} 631 | 632 | \expandafter\def \csname rightsstatementauthor-pays\endcsname{% 633 | \noindent 634 | Permission to make digital or hard copies of part or all of this work for 635 | personal or classroom use is granted without fee provided that copies are 636 | not made or distributed for profit or commercial advantage and that copies 637 | bear this notice and the full citation on the first page. Copyrights for 638 | third-party components of this work must be honored. For all other uses, 639 | contact the Owner/Author(s). \par 640 | \vspace{2pt} 641 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 642 | \noindent Copyright \copyright\ \@copyrightyear\ held by owner/author(s). \par 643 | ACM \@copyrightdata \dots \@reprintprice\par 644 | \setcopyrightdoi} 645 | 646 | % This is the default rights statement. 647 | 648 | \def \rightsstatementlicensed {% 649 | \noindent 650 | Permission to make digital or hard copies of part or all of this work for 651 | personal or classroom use is granted without fee provided that copies are 652 | not made or distributed for profit or commercial advantage and that copies 653 | bear this notice and the full citation on the first page. Copyrights for 654 | components of this work owned by others than ACM must be honored. 655 | Abstracting with credit is permitted. To copy otherwise, to republish, to 656 | post on servers, or to redistribute to lists, contact the Owner/Author(s). 657 | Request permissions from permissions@acm.org or Publications Dept., ACM, 658 | Inc., fax +1~(212) 869-0481. \par 659 | \vspace{2pt} 660 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 661 | \noindent Copyright \copyright\ \@copyrightyear\ held by owner/author(s). Publication rights licensed to ACM. \par 662 | ACM \@copyrightdata \dots \@reprintprice\par 663 | \setcopyrightdoi} 664 | 665 | \if \@notp{\@legacycopyright}% 666 | \publicationrights{licensed}% 667 | \fi 668 | 669 | \def \rightsstatementtransferred {% 670 | \noindent 671 | Permission to make digital or hard copies of part or all of this work for 672 | personal or classroom use is granted without fee provided that copies are 673 | not made or distributed for profit or commercial advantage and that copies 674 | bear this notice and the full citation on the first page. Copyrights for 675 | components of this work owned by others than ACM must be honored. 676 | Abstracting with credit is permitted. To copy otherwise, to republish, to 677 | post on servers, or to redistribute to lists, requires prior specific 678 | permission and/or a fee. Request permissions from permissions@acm.org or 679 | Publications Dept., ACM, Inc., fax +1~(212) 869-0481. \par 680 | \vspace{2pt} 681 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 682 | \noindent Copyright \copyright\ \@copyrightyear\ ACM \@copyrightdata \dots \@reprintprice\par 683 | \setcopyrightdoi} 684 | 685 | \newcommand{\reprintprice}[1]{% 686 | \gdef \@reprintprice {#1}} 687 | 688 | \reprintprice{\$15.00} 689 | 690 | \def \setcopyrightdoi {% 691 | \if \@emptydefp{\@copyrightdoi}% 692 | \if \@andp{\@notp{\@preprint}}{\@notp{\@legacycopyright}}% 693 | \@latex@warning{Copyright DOI has not been provided 694 | (\noexpand\copyrightdoi)}{}% 695 | \fi 696 | \else 697 | \noindent DOI: http://dx.doi.org/10.1145/\@copyrightdoi\par 698 | \fi} 699 | 700 | 701 | % Legacy commands. 702 | 703 | \newcommand{\permission}[1]{% 704 | \gdef \@permission {#1}} 705 | 706 | %%%\permission{% 707 | %%% Permission to make digital or hard copies of part or all of this work for 708 | %%% personal or classroom use is granted without fee provided that copies are 709 | %%% not made or distributed for profit or commercial advantage and that copies 710 | %%% bear this notice and the full citation on the first page. Copyrights for 711 | %%% components of this work owned by others than ACM must be honored. 712 | %%% Abstracting with credit is permitted. To copy otherwise, to republish, to 713 | %%% post on servers, or to redistribute to lists, requires prior specific 714 | %%% permission and/or a fee. Request permissions from permissions@acm.org or 715 | %%% Publications Dept., ACM, Inc., fax +1 (212) 869-0481.} 716 | 717 | % Here we have some alternate permission statements and copyright lines: 718 | 719 | \newcommand{\ACMCanadapermission}{% 720 | \@legacycopyrighterror{\ACMCanadapermission}% 721 | \permission{% 722 | Copyright \@copyrightyear\ Association for Computing Machinery. 723 | ACM acknowledges that 724 | this contribution was authored or co-authored by an affiliate of the 725 | National Research Council of Canada (NRC). 726 | As such, the Crown in Right of 727 | Canada retains an equal interest in the copyright, however granting 728 | nonexclusive, royalty-free right to publish or reproduce this article, 729 | or to allow others to do so, provided that clear attribution 730 | is also given to the authors and the NRC.}} 731 | 732 | \newcommand{\ACMUSpermission}{% 733 | \@legacycopyrighterror{\ACMUSpermission}% 734 | \permission{% 735 | Copyright \@copyrightyear\ Association for 736 | Computing Machinery. ACM acknowledges that 737 | this contribution was authored or co-authored 738 | by a contractor or affiliate 739 | of the U.S. Government. As such, the Government retains a nonexclusive, 740 | royalty-free right to publish or reproduce this article, 741 | or to allow others to do so, for Government purposes only.}} 742 | 743 | \newcommand{\authorpermission}{% 744 | \@legacycopyrighterror{\authorpermission}% 745 | \permission{% 746 | Permission to make digital or hard copies of part or all of this work for 747 | personal or classroom use is granted without fee provided that copies are 748 | not made or distributed for profit or commercial advantage and that copies 749 | bear this notice and the full citation on the first page. Copyrights for 750 | third-party components of this work must be honored. For all other uses, 751 | contact the Owner/Author.}% 752 | \toappear{% 753 | \noindent \@permission \par 754 | \vspace{2pt} 755 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 756 | ACM \@copyrightdata.}} 757 | 758 | \newcommand{\Sunpermission}{% 759 | \@legacycopyrighterror{\Sunpermission}% 760 | \permission{% 761 | Copyright is held by Sun Microsystems, Inc.}% 762 | \toappear{% 763 | \noindent \@permission \par 764 | \vspace{2pt} 765 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 766 | ACM \@copyrightdata.}} 767 | 768 | \newcommand{\USpublicpermission}{% 769 | \@legacycopyrighterror{\USpublicpermission}% 770 | \permission{% 771 | This paper is authored by an employee(s) of the United States 772 | Government and is in the public domain.}% 773 | \toappear{% 774 | \noindent \@permission \par 775 | \vspace{2pt} 776 | \noindent \textsl{\@conferencename}\quad \@conferenceinfo \par 777 | ACM \@copyrightdata.}} 778 | 779 | \newcommand{\authorversion}[4]{% 780 | \@legacycopyrighterror{\authorversion}% 781 | \permission{% 782 | Copyright \copyright\ ACM, #1. This is the author's version of the work. 783 | It is posted here by permission of ACM for your personal use. 784 | Not for redistribution. The definitive version was published in 785 | #2, #3, http://doi.acm.org/10.1145/#4.}} 786 | 787 | \def \exclusivelicense {% 788 | \@latex@error{Deprecated; 789 | you probably want `\noexpand\publicationrights{licensed}'}{}} 790 | 791 | \def \permissiontopublish {% 792 | \@latex@error{Deprecated; 793 | you probably want `\noexpand\publicationrights{author-pays}'}{}} 794 | 795 | \def \@legacycopyrighterror #1{% 796 | \if \@notp{\@legacycopyright}% 797 | \@latex@error{Copyright permission '\noexpand#1' is deprecated; use 798 | 'legacycopyright' class option to allow it}{}% 799 | \fi} 800 | 801 | % Enunciations 802 | % ------------ 803 | 804 | 805 | \def \@begintheorem #1#2{% {name}{number} 806 | \trivlist 807 | \item[\hskip \labelsep \textsc{#1 #2.}]% 808 | \itshape\selectfont 809 | \ignorespaces} 810 | 811 | \def \@opargbegintheorem #1#2#3{% {name}{number}{title} 812 | \trivlist 813 | \item[% 814 | \hskip\labelsep \textsc{#1\ #2}% 815 | \if \@notp{\@emptyargp{#3}}\nut (#3).\fi]% 816 | \itshape\selectfont 817 | \ignorespaces} 818 | 819 | % Figures 820 | % ------- 821 | 822 | 823 | \@setflag \@caprule = \@true 824 | 825 | \long\def \@makecaption #1#2{% 826 | \addvspace{4pt} 827 | \if \@caprule 828 | \hrule width \hsize height .33pt 829 | \vspace{4pt} 830 | \fi 831 | \setbox \@tempboxa = \hbox{\@setfigurenumber{#1.}\nut #2}% 832 | \if \@dimgtrp{\wd\@tempboxa}{\hsize}% 833 | \noindent \@setfigurenumber{#1.}\nut #2\par 834 | \else 835 | \centerline{\box\@tempboxa}% 836 | \fi} 837 | 838 | \newcommand{\nocaptionrule}{% 839 | \@setflag \@caprule = \@false} 840 | 841 | \def \@setfigurenumber #1{% 842 | {\rmfamily \bfseries \selectfont #1}} 843 | 844 | % Hierarchy 845 | % --------- 846 | 847 | 848 | \setcounter{secnumdepth}{\@numheaddepth} 849 | 850 | \newskip{\@sectionaboveskip} 851 | \setvspace{\@sectionaboveskip}{10pt plus 3pt minus 2pt} 852 | 853 | \newskip{\@sectionbelowskip} 854 | \if \@blockstyle 855 | \setlength{\@sectionbelowskip}{0.1pt}% 856 | \else 857 | \setlength{\@sectionbelowskip}{4pt}% 858 | \fi 859 | 860 | \renewcommand{\section}{% 861 | \@startsection 862 | {section}% 863 | {1}% 864 | {0pt}% 865 | {-\@sectionaboveskip}% 866 | {\@sectionbelowskip}% 867 | {\large \bfseries \raggedright}} 868 | 869 | \newskip{\@subsectionaboveskip} 870 | \setvspace{\@subsectionaboveskip}{8pt plus 2pt minus 2pt} 871 | 872 | \newskip{\@subsectionbelowskip} 873 | \if \@blockstyle 874 | \setlength{\@subsectionbelowskip}{0.1pt}% 875 | \else 876 | \setlength{\@subsectionbelowskip}{4pt}% 877 | \fi 878 | 879 | \renewcommand{\subsection}{% 880 | \@startsection% 881 | {subsection}% 882 | {2}% 883 | {0pt}% 884 | {-\@subsectionaboveskip}% 885 | {\@subsectionbelowskip}% 886 | {\normalsize \bfseries \raggedright}} 887 | 888 | \renewcommand{\subsubsection}{% 889 | \@startsection% 890 | {subsubsection}% 891 | {3}% 892 | {0pt}% 893 | {-\@subsectionaboveskip} 894 | {\@subsectionbelowskip}% 895 | {\normalsize \bfseries \raggedright}} 896 | 897 | \newskip{\@paragraphaboveskip} 898 | \setvspace{\@paragraphaboveskip}{6pt plus 2pt minus 2pt} 899 | 900 | \renewcommand{\paragraph}{% 901 | \@startsection% 902 | {paragraph}% 903 | {4}% 904 | {0pt}% 905 | {\@paragraphaboveskip} 906 | {-1em}% 907 | {\normalsize \bfseries \if \@times \itshape \fi}} 908 | 909 | \renewcommand{\subparagraph}{% 910 | \@startsection% 911 | {subparagraph}% 912 | {4}% 913 | {0pt}% 914 | {\@paragraphaboveskip} 915 | {-1em}% 916 | {\normalsize \itshape}} 917 | 918 | % Standard headings: 919 | 920 | \newcommand{\acks}{\section*{Acknowledgments}} 921 | 922 | \newcommand{\keywords}{\paragraph*{Keywords}} 923 | 924 | \newcommand{\terms}{\paragraph*{General Terms}} 925 | 926 | % Identification 927 | % -------------- 928 | 929 | 930 | \def \@conferencename {} 931 | \def \@conferenceinfo {} 932 | \def \@copyrightyear {} 933 | \def \@copyrightdata {[to be supplied]} 934 | \def \@copyrightdoi {} 935 | \def \@proceedings {[Unknown Proceedings]} 936 | 937 | 938 | \newcommand{\conferenceinfo}[2]{% 939 | \gdef \@conferencename {#1}% 940 | \gdef \@conferenceinfo {#2}} 941 | 942 | \newcommand{\copyrightyear}[1]{% 943 | \gdef \@copyrightyear {#1}} 944 | 945 | \let \CopyrightYear = \copyrightyear 946 | 947 | \newcommand{\copyrightdata}[1]{% 948 | \gdef \@copyrightdata {#1}} 949 | 950 | \let \crdata = \copyrightdata 951 | 952 | \newcommand{\proceedings}[1]{% 953 | \gdef \@proceedings {#1}} 954 | 955 | \def \copyrightDOI #1{% 956 | \gdef \@copyrightdoi {#1}} 957 | 958 | \let \copyrightdoi = \copyrightDOI 959 | 960 | % Lists 961 | % ----- 962 | 963 | 964 | \setlength{\leftmargini}{13pt} 965 | \setlength\leftmarginii{13pt} 966 | \setlength\leftmarginiii{13pt} 967 | \setlength\leftmarginiv{13pt} 968 | \setlength{\labelsep}{3.5pt} 969 | 970 | \setlength{\topsep}{\standardvspace} 971 | \if \@blockstyle 972 | \setlength{\itemsep}{1pt} 973 | \setlength{\parsep}{3pt} 974 | \else 975 | \setlength{\itemsep}{1pt} 976 | \setlength{\parsep}{3pt} 977 | \fi 978 | 979 | \renewcommand{\labelitemi}{{\small \centeroncapheight{\textbullet}}} 980 | \renewcommand{\labelitemii}{\centeroncapheight{\rule{2.5pt}{2.5pt}}} 981 | \renewcommand{\labelitemiii}{$-$} 982 | \renewcommand{\labelitemiv}{{\Large \textperiodcentered}} 983 | 984 | \renewcommand{\@listi}{% 985 | \leftmargin = \leftmargini 986 | \listparindent = 0pt} 987 | %%% \itemsep = 1pt 988 | %%% \parsep = 3pt} 989 | %%% \listparindent = \parindent} 990 | 991 | \let \@listI = \@listi 992 | 993 | \renewcommand{\@listii}{% 994 | \leftmargin = \leftmarginii 995 | \topsep = 1pt 996 | \labelwidth = \leftmarginii 997 | \advance \labelwidth by -\labelsep 998 | \listparindent = \parindent} 999 | 1000 | \renewcommand{\@listiii}{% 1001 | \leftmargin = \leftmarginiii 1002 | \labelwidth = \leftmarginiii 1003 | \advance \labelwidth by -\labelsep 1004 | \listparindent = \parindent} 1005 | 1006 | \renewcommand{\@listiv}{% 1007 | \leftmargin = \leftmarginiv 1008 | \labelwidth = \leftmarginiv 1009 | \advance \labelwidth by -\labelsep 1010 | \listparindent = \parindent} 1011 | 1012 | % Mathematics 1013 | % ----------- 1014 | 1015 | 1016 | \def \theequation {\arabic{equation}} 1017 | 1018 | % Miscellaneous 1019 | % ------------- 1020 | 1021 | 1022 | \newcommand{\balancecolumns}{% 1023 | \vfill\eject 1024 | \global\@colht = \textheight 1025 | \global\ht\@cclv = \textheight} 1026 | 1027 | \newcommand{\nut}{\hspace{.5em}} 1028 | 1029 | \newcommand{\softraggedright}{% 1030 | \let \\ = \@centercr 1031 | \leftskip = 0pt 1032 | \rightskip = 0pt plus 10pt} 1033 | 1034 | % Program Code 1035 | % ------- ---- 1036 | 1037 | 1038 | \newcommand{\mono}[1]{% 1039 | {\@tempdima = \fontdimen2\font 1040 | \texttt{\spaceskip = 1.1\@tempdima #1}}} 1041 | 1042 | % Running Heads and Feet 1043 | % ------- ----- --- ---- 1044 | 1045 | 1046 | \def \@preprintfooter {} 1047 | 1048 | \newcommand{\preprintfooter}[1]{% 1049 | \gdef \@preprintfooter {#1}} 1050 | 1051 | \if \@preprint 1052 | 1053 | \def \ps@plain {% 1054 | \let \@mkboth = \@gobbletwo 1055 | \let \@evenhead = \@empty 1056 | \def \@evenfoot {\scriptsize 1057 | \rlap{\textit{\@preprintfooter}}\hfil 1058 | \thepage \hfil 1059 | \llap{\textit{\@formatyear}}}% 1060 | \let \@oddhead = \@empty 1061 | \let \@oddfoot = \@evenfoot} 1062 | 1063 | \else\if \@reprint 1064 | 1065 | \def \ps@plain {% 1066 | \let \@mkboth = \@gobbletwo 1067 | \let \@evenhead = \@empty 1068 | \def \@evenfoot {\scriptsize \hfil \thepage \hfil}% 1069 | \let \@oddhead = \@empty 1070 | \let \@oddfoot = \@evenfoot} 1071 | 1072 | \else 1073 | 1074 | \let \ps@plain = \ps@empty 1075 | \let \ps@headings = \ps@empty 1076 | \let \ps@myheadings = \ps@empty 1077 | 1078 | \fi\fi 1079 | 1080 | \def \@formatyear {% 1081 | \number\year/\number\month/\number\day} 1082 | 1083 | % Special Characters 1084 | % ------- ---------- 1085 | 1086 | 1087 | \DeclareRobustCommand{\euro}{% 1088 | \protect{\rlap{=}}{\sf \kern .1em C}} 1089 | 1090 | % Title Page 1091 | % ----- ---- 1092 | 1093 | 1094 | \@setflag \@addauthorsdone = \@false 1095 | 1096 | \def \@titletext {\@latex@error{No title was provided}{}} 1097 | \def \@subtitletext {} 1098 | 1099 | \newcount{\@authorcount} 1100 | 1101 | \newcount{\@titlenotecount} 1102 | \newtoks{\@titlenotetext} 1103 | 1104 | \def \@titlebanner {} 1105 | 1106 | \renewcommand{\title}[1]{% 1107 | \gdef \@titletext {#1}} 1108 | 1109 | \newcommand{\subtitle}[1]{% 1110 | \gdef \@subtitletext {#1}} 1111 | 1112 | \newcommand{\authorinfo}[3]{% {names}{affiliation}{email/URL} 1113 | \global\@increment \@authorcount 1114 | \@withname\gdef {\@authorname\romannumeral\@authorcount}{#1}% 1115 | \@withname\gdef {\@authoraffil\romannumeral\@authorcount}{#2}% 1116 | \@withname\gdef {\@authoremail\romannumeral\@authorcount}{#3}} 1117 | 1118 | \renewcommand{\author}[1]{% 1119 | \@latex@error{The \string\author\space command is obsolete; 1120 | use \string\authorinfo}{}} 1121 | 1122 | \newcommand{\titlebanner}[1]{% 1123 | \gdef \@titlebanner {#1}} 1124 | 1125 | \renewcommand{\maketitle}{% 1126 | \pagestyle{plain}% 1127 | \if \@onecolumn 1128 | {\hsize = \standardtextwidth 1129 | \@maketitle}% 1130 | \else 1131 | \twocolumn[\@maketitle]% 1132 | \fi 1133 | \@placetitlenotes 1134 | \if \@copyrightwanted \@copyrightspace \fi} 1135 | 1136 | \def \@maketitle {% 1137 | \begin{center} 1138 | \@settitlebanner 1139 | \let \thanks = \titlenote 1140 | {\leftskip = 0pt plus 0.25\linewidth 1141 | \rightskip = 0pt plus 0.25 \linewidth 1142 | \parfillskip = 0pt 1143 | \spaceskip = .7em 1144 | \noindent \LARGE \bfseries \@titletext \par} 1145 | \vskip 6pt 1146 | \noindent \Large \@subtitletext \par 1147 | \vskip 12pt 1148 | \ifcase \@authorcount 1149 | \@latex@error{No authors were specified for this paper}{}\or 1150 | \@titleauthors{i}{}{}\or 1151 | \@titleauthors{i}{ii}{}\or 1152 | \@titleauthors{i}{ii}{iii}\or 1153 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{}{}\or 1154 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{}\or 1155 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}\or 1156 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1157 | \@titleauthors{vii}{}{}\or 1158 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1159 | \@titleauthors{vii}{viii}{}\or 1160 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1161 | \@titleauthors{vii}{viii}{ix}\or 1162 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1163 | \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{}{}\or 1164 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1165 | \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{xi}{}\or 1166 | \@titleauthors{i}{ii}{iii}\@titleauthors{iv}{v}{vi}% 1167 | \@titleauthors{vii}{viii}{ix}\@titleauthors{x}{xi}{xii}% 1168 | \else 1169 | \@latex@error{Cannot handle more than 12 authors}{}% 1170 | \fi 1171 | \vspace{1.75pc} 1172 | \end{center}} 1173 | 1174 | \def \@settitlebanner {% 1175 | \if \@andp{\@orp{\@preprint}{\@reprint}} 1176 | {\@notp{\@emptydefp{\@titlebanner}}}% 1177 | \vbox to 0pt{% 1178 | \vskip -32pt 1179 | \noindent \textbf{\@titlebanner}\par 1180 | \vss}% 1181 | \nointerlineskip 1182 | \fi} 1183 | 1184 | \def \@titleauthors #1#2#3{% 1185 | \if \@andp{\@emptyargp{#2}}{\@emptyargp{#3}}% 1186 | \noindent \@setauthor{40pc}{#1}{\@false}\par 1187 | \else\if \@emptyargp{#3}% 1188 | \noindent \@setauthor{17pc}{#1}{\@false}\hspace{3pc}% 1189 | \@setauthor{17pc}{#2}{\@false}\par 1190 | \else 1191 | \noindent \@setauthor{12.5pc}{#1}{\@false}\hspace{2pc}% 1192 | \@setauthor{12.5pc}{#2}{\@false}\hspace{2pc}% 1193 | \@setauthor{12.5pc}{#3}{\@true}\par 1194 | \relax 1195 | \fi\fi 1196 | \vspace{20pt}} 1197 | 1198 | \def \@setauthor #1#2#3{% {width}{text}{unused} 1199 | \vtop{% 1200 | \def \and {% 1201 | \hspace{16pt}} 1202 | \hsize = #1 1203 | \normalfont 1204 | \centering 1205 | \large \@name{\@authorname#2}\par 1206 | \vspace{5pt} 1207 | \normalsize \@name{\@authoraffil#2}\par 1208 | \vspace{2pt} 1209 | \textsf{\@name{\@authoremail#2}}\par}} 1210 | 1211 | \def \@maybetitlenote #1{% 1212 | \if \@andp{#1}{\@gtrp{\@authorcount}{3}}% 1213 | \titlenote{See page~\pageref{@addauthors} for additional authors.}% 1214 | \fi} 1215 | 1216 | \newtoks{\@fnmark} 1217 | 1218 | \newcommand{\titlenote}[1]{% 1219 | \global\@increment \@titlenotecount 1220 | \ifcase \@titlenotecount \relax \or 1221 | \@fnmark = {\ast}\or 1222 | \@fnmark = {\dagger}\or 1223 | \@fnmark = {\ddagger}\or 1224 | \@fnmark = {\S}\or 1225 | \@fnmark = {\P}\or 1226 | \@fnmark = {\ast\ast}% 1227 | \fi 1228 | \,$^{\the\@fnmark}$% 1229 | \edef \reserved@a {\noexpand\@appendtotext{% 1230 | \noexpand\@titlefootnote{\the\@fnmark}}}% 1231 | \reserved@a{#1}} 1232 | 1233 | \def \@appendtotext #1#2{% 1234 | \global\@titlenotetext = \expandafter{\the\@titlenotetext #1{#2}}} 1235 | 1236 | \newcount{\@authori} 1237 | 1238 | \iffalse 1239 | \def \additionalauthors {% 1240 | \if \@gtrp{\@authorcount}{3}% 1241 | \section{Additional Authors}% 1242 | \label{@addauthors}% 1243 | \noindent 1244 | \@authori = 4 1245 | {\let \\ = ,% 1246 | \loop 1247 | \textbf{\@name{\@authorname\romannumeral\@authori}}, 1248 | \@name{\@authoraffil\romannumeral\@authori}, 1249 | email: \@name{\@authoremail\romannumeral\@authori}.% 1250 | \@increment \@authori 1251 | \if \@notp{\@gtrp{\@authori}{\@authorcount}} \repeat}% 1252 | \par 1253 | \fi 1254 | \global\@setflag \@addauthorsdone = \@true} 1255 | \fi 1256 | 1257 | \let \addauthorsection = \additionalauthors 1258 | 1259 | \def \@placetitlenotes { 1260 | \the\@titlenotetext} 1261 | 1262 | % Utilities 1263 | % --------- 1264 | 1265 | 1266 | \newcommand{\centeroncapheight}[1]{% 1267 | {\setbox\@tempboxa = \hbox{#1}% 1268 | \@measurecapheight{\@tempdima}% % Calculate ht(CAP) - ht(text) 1269 | \advance \@tempdima by -\ht\@tempboxa % ------------------ 1270 | \divide \@tempdima by 2 % 2 1271 | \raise \@tempdima \box\@tempboxa}} 1272 | 1273 | \newbox{\@measbox} 1274 | 1275 | \def \@measurecapheight #1{% {\dimen} 1276 | \setbox\@measbox = \hbox{ABCDEFGHIJKLMNOPQRSTUVWXYZ}% 1277 | #1 = \ht\@measbox} 1278 | 1279 | \long\def \@titlefootnote #1#2{% 1280 | \insert\footins{% 1281 | \reset@font\footnotesize 1282 | \interlinepenalty\interfootnotelinepenalty 1283 | \splittopskip\footnotesep 1284 | \splitmaxdepth \dp\strutbox \floatingpenalty \@MM 1285 | \hsize\columnwidth \@parboxrestore 1286 | %%% \protected@edef\@currentlabel{% 1287 | %%% \csname p@footnote\endcsname\@thefnmark}% 1288 | \color@begingroup 1289 | \def \@makefnmark {$^{#1}$}% 1290 | \@makefntext{% 1291 | \rule\z@\footnotesep\ignorespaces#2\@finalstrut\strutbox}% 1292 | \color@endgroup}} 1293 | 1294 | % LaTeX Modifications 1295 | % ----- ------------- 1296 | 1297 | \def \@seccntformat #1{% 1298 | \@name{\the#1}% 1299 | \@expandaftertwice\@seccntformata \csname the#1\endcsname.\@mark 1300 | \quad} 1301 | 1302 | \def \@seccntformata #1.#2\@mark{% 1303 | \if \@emptyargp{#2}.\fi} 1304 | 1305 | % Revision History 1306 | % -------- ------- 1307 | 1308 | 1309 | % Date Person Ver. Change 1310 | % ---- ------ ---- ------ 1311 | 1312 | % 2004.09.12 PCA 0.1--4 Preliminary development. 1313 | 1314 | % 2004.11.18 PCA 0.5 Start beta testing. 1315 | 1316 | % 2004.11.19 PCA 0.6 Obsolete \author and replace with 1317 | % \authorinfo. 1318 | % Add 'nocopyrightspace' option. 1319 | % Compress article opener spacing. 1320 | % Add 'mathtime' option. 1321 | % Increase text height by 6 points. 1322 | 1323 | % 2004.11.28 PCA 0.7 Add 'cm/computermodern' options. 1324 | % Change default to Times text. 1325 | 1326 | % 2004.12.14 PCA 0.8 Remove use of mathptm.sty; it cannot 1327 | % coexist with latexsym or amssymb. 1328 | 1329 | % 2005.01.20 PCA 0.9 Rename class file to sigplanconf.cls. 1330 | 1331 | % 2005.03.05 PCA 0.91 Change default copyright data. 1332 | 1333 | % 2005.03.06 PCA 0.92 Add at-signs to some macro names. 1334 | 1335 | % 2005.03.07 PCA 0.93 The 'onecolumn' option defaults to '11pt', 1336 | % and it uses the full type width. 1337 | 1338 | % 2005.03.15 PCA 0.94 Add at-signs to more macro names. 1339 | % Allow margin paragraphs during review. 1340 | 1341 | % 2005.03.22 PCA 0.95 Implement \euro. 1342 | % Remove proof and newdef environments. 1343 | 1344 | % 2005.05.06 PCA 1.0 Eliminate 'onecolumn' option. 1345 | % Change footer to small italic and eliminate 1346 | % left portion if no \preprintfooter. 1347 | % Eliminate copyright notice if preprint. 1348 | % Clean up and shrink copyright box. 1349 | 1350 | % 2005.05.30 PCA 1.1 Add alternate permission statements. 1351 | 1352 | % 2005.06.29 PCA 1.1 Publish final first edition of guide. 1353 | 1354 | % 2005.07.14 PCA 1.2 Add \subparagraph. 1355 | % Use block paragraphs in lists, and adjust 1356 | % spacing between items and paragraphs. 1357 | 1358 | % 2006.06.22 PCA 1.3 Add 'reprint' option and associated 1359 | % commands. 1360 | 1361 | % 2006.08.24 PCA 1.4 Fix bug in \maketitle case command. 1362 | 1363 | % 2007.03.13 PCA 1.5 The title banner only displays with the 1364 | % 'preprint' option. 1365 | 1366 | % 2007.06.06 PCA 1.6 Use \bibfont in \thebibliography. 1367 | % Add 'natbib' option to load and configure 1368 | % the natbib package. 1369 | 1370 | % 2007.11.20 PCA 1.7 Balance line lengths in centered article 1371 | % title (thanks to Norman Ramsey). 1372 | 1373 | % 2009.01.26 PCA 1.8 Change natbib \bibpunct values. 1374 | 1375 | % 2009.03.24 PCA 1.9 Change natbib to use the 'numbers' option. 1376 | % Change templates to use 'natbib' option. 1377 | 1378 | % 2009.09.01 PCA 2.0 Add \reprintprice command (suggested by 1379 | % Stephen Chong). 1380 | 1381 | % 2009.09.08 PCA 2.1 Make 'natbib' the default; add 'nonatbib'. 1382 | % SB Add 'authoryear' and 'numbers' (default) to 1383 | % control citation style when using natbib. 1384 | % Add \bibpunct to change punctuation for 1385 | % 'authoryear' style. 1386 | 1387 | % 2009.09.21 PCA 2.2 Add \softraggedright to the thebibliography 1388 | % environment. Also add to template so it will 1389 | % happen with natbib. 1390 | 1391 | % 2009.09.30 PCA 2.3 Remove \softraggedright from thebibliography. 1392 | % Just include in the template. 1393 | 1394 | % 2010.05.24 PCA 2.4 Obfuscate class author's email address. 1395 | 1396 | % 2011.11.08 PCA 2.5 Add copyright notice to this file. 1397 | % Remove 'sort' option from natbib when using 1398 | % 'authoryear' style. 1399 | % Add the \authorversion command. 1400 | 1401 | % 2013.02.22 PCA 2.6 Change natbib fences to parentheses when 1402 | % using 'authoryear' style. 1403 | 1404 | % 2013.05.17 PCA 2.7 Change standard and author copyright text. 1405 | 1406 | % 2.8 (retracted) 1407 | 1408 | % 2014.07.30 PCA 2.9 Created just to replace version 2.8. 1409 | 1410 | % 2014.08.14 PCA 3.0 Implement new copyright command as specified 1411 | % at github.com/SIGPLAN/online/wiki/ 1412 | % ACM-SIGPLAN-%28c%29-Messages 1413 | % Deprecate the old commands, but allow their 1414 | % use with the 'legacycopyright' option. 1415 | 1416 | % 2015.04.13 PCA 3.1 Add warning to program chairs. 1417 | % Use package mathptmx instead of mathptm. 1418 | % Display title banner when 'reprint' option 1419 | % specified. 1420 | % Make authoryear citation style the default. 1421 | % Change copyright box size back to 1 inch and 1422 | % shrink text to \tiny size. 1423 | % DOI takes up no space when not provided. 1424 | % DOI warning does not appear when 1425 | % 'legacycopyright' option specified. 1426 | % 'legacycopyright' option without \permission 1427 | % produces warning text in copyright box. 1428 | 1429 | % 2015.12.03 MTF 3.2 Remove use of package mathptmx. No prior 1430 | % released version used package mathptm. 1431 | 1432 | % 2016.02.14 MTF 3.2b Tweak copyright and publisher lines for 1433 | % \publicationrights{author-pays} and 1434 | % \publicationrights{licensed} 1435 | --------------------------------------------------------------------------------