Skip to content

Commit

Permalink
Use a record type Globals collecting scopes for definitions, construc…
Browse files Browse the repository at this point in the history
…tors, and their fields
  • Loading branch information
jespercockx committed Jan 17, 2024
1 parent f2e8d9c commit bd95f4b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 83 deletions.
15 changes: 5 additions & 10 deletions src/Context.agda
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

open import Scope.Core
open import Scope.Split
open import Scope.Sub
open import Scope.In
open import Scope.All
open import Scope
open import GlobalScope

open import Haskell.Extra.Dec
open import Utils.Either
Expand All @@ -17,13 +14,11 @@ import Reduce

module Context
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 globals : Globals)
where

open Syntax defs cons conArity
open Reduce defs cons conArity
open Syntax globals
open Reduce globals

private variable
@0 x y : name
Expand Down
21 changes: 8 additions & 13 deletions src/Conversion.agda
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
open import Scope.Core
open import Scope.Split
open import Scope.Sub
open import Scope.In
open import Scope.All
open import Scope
open import GlobalScope

open import Haskell.Extra.Dec
open import Utils.Either
Expand All @@ -15,16 +12,14 @@ import Syntax

module Conversion
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 defType : All (λ _ Syntax.Type defs cons conArity mempty) defs)
(@0 globals : Globals)
(@0 defType : All (λ _ Syntax.Type globals mempty) (Globals.defScope globals))
where

open Syntax defs cons conArity
open import Substitute defs cons conArity
open import Reduce defs cons conArity
open import Context defs cons conArity
open Syntax globals
open import Substitute globals
open import Reduce globals
open import Context globals

private variable
@0 x y z : name
Expand Down
12 changes: 12 additions & 0 deletions src/GlobalScope.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

open import Scope

open import Haskell.Prelude hiding (All; s; t)

module GlobalScope {@0 name : Set} where

record Globals : Set where
field
defScope : Scope name
conScope : Scope name
fieldScope : All (λ _ Scope name) conScope
21 changes: 8 additions & 13 deletions src/Reduce.agda
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

open import Scope.Core
open import Scope.Split
open import Scope.Sub
open import Scope.In
open import Scope.All
open import Scope
open import GlobalScope

open import Haskell.Extra.Dec
open import Haskell.Extra.Loop
Expand All @@ -20,13 +17,11 @@ import Substitute

module Reduce
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 globals : Globals)
where

open Syntax defs cons conArity
open Substitute defs cons conArity
open Syntax globals
open Substitute globals

private variable
@0 x : name
Expand Down Expand Up @@ -83,9 +78,9 @@ unState r (MkState e v s) = substTerm (envToSubst r e) (applyElims v s)

{-# COMPILE AGDA2HS unState #-}

lookupBranch : Branches α (@0 c : name) (p : c ∈ cons)
Maybe ( Rezz _ (lookupAll conArity p)
× Term ((lookupAll conArity p) <> α))
lookupBranch : Branches α (@0 c : name) (p : c ∈ conScope)
Maybe ( Rezz _ (lookupAll fieldScope p)
× Term ((lookupAll fieldScope p) <> α))
lookupBranch [] c k = Nothing
lookupBranch (BBranch c' k' aty u ∷ bs) c p =
case decIn k' p of λ where
Expand Down
15 changes: 5 additions & 10 deletions src/Substitute.agda
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@

open import Scope.Core
open import Scope.Split
open import Scope.Sub
open import Scope.In
open import Scope.All
open import Scope
open import GlobalScope

open import Haskell.Extra.Dec
open import Haskell.Extra.Erase
open import Utils.Either

open import Haskell.Prelude hiding (All)

module Substitute
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 globalS : Globals)
where

open import Syntax defs cons conArity
open import Haskell.Extra.Erase
open import Syntax globalS

private variable
@0 x : name
Expand Down
23 changes: 12 additions & 11 deletions src/Syntax.agda
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ open import Haskell.Extra.Erase

open import Utils.Misc

-- NOTE(flupe): make Scope export all of the following
open import Scope
open import GlobalScope

module Syntax
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 globals : Globals)
where

module @0 TheGlobals = Globals globals
open TheGlobals public

private variable
@0 x : name
@0 α β γ : Scope name
Expand Down Expand Up @@ -48,9 +49,9 @@ syntax Subst α β = α ⇒ β
data Term α where
-- NOTE(flupe): removed tactic arguments for now because hidden arguments not supported yet #217
TVar : (@0 x : name) x ∈ α Term α
TDef : (@0 d : name) d ∈ defs Term α
TCon : (@0 c : name) (c∈cons : c ∈ cons)
(lookupAll conArity c∈cons) ⇒ α Term α
TDef : (@0 d : name) d ∈ defScope Term α
TCon : (@0 c : name) (c∈cons : c ∈ conScope)
(lookupAll fieldScope c∈cons) ⇒ α Term α
TLam : (@0 x : name) (v : Term (x ◃ α)) Term α
TApp : (u : Term α) (es : Elim α) Term α
TPi : (@0 x : name) (su sv : Sort α) (u : Term α) (v : Term (x ◃ α)) Term α
Expand All @@ -71,7 +72,7 @@ funSort (STyp a) (STyp b) = STyp (max a b)

data Elim α where
EArg : Term α Elim α
EProj : (@0 x : name) x ∈ defs Elim α
EProj : (@0 x : name) x ∈ defScope Elim α
ECase : (bs : Branches α) Elim α
-- TODO: do we need a type annotation for the return type of case?
{-# COMPILE AGDA2HS Elim #-}
Expand All @@ -80,9 +81,9 @@ Elims α = List (Elim α)
{-# COMPILE AGDA2HS Elims #-}

data Branch α where
BBranch : (@0 c : name) (c∈cons : c ∈ cons)
Rezz _ (lookupAll conArity c∈cons)
Term (lookupAll conArity c∈cons <> α) Branch α
BBranch : (@0 c : name) (c∈cons : c ∈ conScope)
Rezz _ (lookupAll fieldScope c∈cons)
Term (lookupAll fieldScope c∈cons <> α) Branch α
{-# COMPILE AGDA2HS Branch #-}

Branches α = List (Branch α)
Expand Down
18 changes: 11 additions & 7 deletions src/TestReduce.agda
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ open import Haskell.Extra.Erase
open import Haskell.Extra.Refinement
open import Haskell.Extra.Delay

open import Scope.Core
open import Scope.In
open import Scope.All
open import Scope.Split
open import Scope.Sub
open import Scope
open import GlobalScope

name = String

Expand All @@ -34,8 +31,15 @@ cons = bind "true" $ bind "false" mempty
conArity : All (λ _ Scope name) cons
conArity = allJoin (allSingl mempty) (allJoin (allSingl mempty) allEmpty)

open import Syntax defs cons conArity
open import Reduce defs cons conArity
globals : Globals
globals = record
{ defScope = defs
; conScope = cons
; fieldScope = conArity
}

open import Syntax globals
open import Reduce globals

opaque
unfolding lookupAll inHere inThere splitRefl splitJoinRight subBindDrop subLeft
Expand Down
17 changes: 8 additions & 9 deletions src/Typechecker.agda
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# OPTIONS --allow-unsolved-metas #-}
open import Scope
open import GlobalScope
import Syntax
import Reduce
import Typing
Expand All @@ -14,16 +15,14 @@ open import Agda.Primitive

module Typechecker
{@0 name : Set}
(defs : Scope name)
(cons : Scope name)
(conArity : All (λ _ Scope name) cons)
(defType : All (λ _ Syntax.Type defs cons conArity mempty) defs)
(@0 globals : Globals)
(defType : All (λ _ Syntax.Type globals (mempty {{iMonoidScope}})) (Globals.defScope globals))
where

open Syntax defs cons conArity
open Typing defs cons conArity defType
open Context defs cons conArity
open Conversion defs cons conArity defType
open Syntax globals
open Context globals
open Conversion globals defType
open Typing globals defType

private
variable @0 α : Scope name
Expand Down Expand Up @@ -82,7 +81,7 @@ inferTySort : (s : Sort α)
inferTySort = {!!}

checkDef : (@0 f : name)
(p : f ∈ defs)
(p : f ∈ defScope)
(ty : Type α)
TCM (Γ ⊢ TDef f p ∷ ty)
checkDef = {!!}
Expand Down
19 changes: 9 additions & 10 deletions src/Typing.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- open import Utils
-- open Variables
open import Scope
open import GlobalScope
import Syntax
import Reduce
import Context
Expand All @@ -14,17 +15,15 @@ open import Haskell.Extra.Loop

module Typing
{@0 name : Set}
(@0 defs : Scope name)
(@0 cons : Scope name)
(@0 conArity : All (λ _ Scope name) cons)
(@0 defType : All (λ _ Syntax.Type defs cons conArity mempty) defs)
(@0 globals : Globals)
(@0 defType : All (λ _ Syntax.Type globals (mempty {{iMonoidScope}})) (Globals.defScope globals))
where

open Syntax defs cons conArity
open Reduce defs cons conArity
open Context defs cons conArity
open Conversion defs cons conArity defType
open Substitute defs cons conArity
open Syntax globals
open Substitute globals
open Reduce globals
open Context globals
open Conversion globals defType

private variable
@0 x y : name
Expand Down Expand Up @@ -57,7 +56,7 @@ data TyTerm {α} Γ where
-------------------
Γ ⊢ TVar x p ∷ (lookupVar Γ x p)

TyDef : (@0 f : name) {@0 p : f ∈ defs}
TyDef : (@0 f : name) {@0 p : f ∈ defScope}

-------------------------------------------------
Γ ⊢ TDef f p ∷ (weaken subEmpty (defType ! f))
Expand Down

0 comments on commit bd95f4b

Please sign in to comment.