deriving
This commit is contained in:
parent
ba3612d836
commit
ce3342f330
6 changed files with 29 additions and 62 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
build
|
|
||||||
.build
|
.build
|
||||||
|
build
|
||||||
depends
|
depends
|
||||||
|
*.ipkg
|
||||||
*~
|
*~
|
||||||
|
|
|
@ -10,7 +10,13 @@
|
||||||
|
|
||||||
"deps" : [
|
"deps" : [
|
||||||
{ "name" : "base", "legacy" : true },
|
{ "name" : "base", "legacy" : true },
|
||||||
{ "name" : "contrib", "legacy" : true }
|
{ "name" : "contrib", "legacy" : true },
|
||||||
|
{ "name" : "sop",
|
||||||
|
"git" : {
|
||||||
|
"url" : "https://git.rhiannon.website/rhi/idris2-sop",
|
||||||
|
"commit" : "defdbc74a28104a32149922ed9f9ee70099d4f59"
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"modules" : [
|
"modules" : [
|
||||||
|
|
|
@ -4,8 +4,10 @@ import Quox.Error
|
||||||
|
|
||||||
import Data.String
|
import Data.String
|
||||||
import public Text.Lexer
|
import public Text.Lexer
|
||||||
|
import Generics.Derive
|
||||||
|
|
||||||
%default total
|
%default total
|
||||||
|
%language ElabReflection
|
||||||
|
|
||||||
|
|
||||||
public export
|
public export
|
||||||
|
@ -25,25 +27,7 @@ data Punc
|
||||||
| Times | Triangle
|
| Times | Triangle
|
||||||
| Wild
|
| Wild
|
||||||
|
|
||||||
puncRepr : Punc -> Nat
|
%runElab derive "Punc" [Generic, Meta, Eq, Ord, DecEq, Show]
|
||||||
puncRepr = \case
|
|
||||||
LParen => 0; RParen => 1; LSquare => 2; RSquare => 3
|
|
||||||
LBrace => 4; RBrace => 5; Comma => 5
|
|
||||||
Colon => 6; DblColon => 7; Arrow => 8; DblArrow => 9
|
|
||||||
Times => 10; Triangle => 11
|
|
||||||
Wild => 12
|
|
||||||
|
|
||||||
export Eq Punc where (==) = (==) `on` puncRepr
|
|
||||||
export Ord Punc where compare = compare `on` puncRepr
|
|
||||||
|
|
||||||
export
|
|
||||||
Show Punc where
|
|
||||||
show = \case
|
|
||||||
LParen => "'('"; RParen => "')'"; LSquare => "'['"; RSquare => "']'"
|
|
||||||
LBrace => "'{'"; RBrace => "'}'"; Comma => "','"
|
|
||||||
Colon => "':'"; DblColon => "'∷'"; Arrow => "'→'"; DblArrow => "'⇒'"
|
|
||||||
Times => "'×'"; Triangle => "'⊲'"
|
|
||||||
Wild => "'_'"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,19 +36,7 @@ data Kind
|
||||||
= P Punc
|
= P Punc
|
||||||
| Name | Symbol
|
| Name | Symbol
|
||||||
|
|
||||||
kindRepr : Kind -> (Nat, Nat)
|
%runElab derive "Kind" [Generic, Meta, Eq, Ord, DecEq, Show]
|
||||||
kindRepr (P p) = (0, puncRepr p)
|
|
||||||
kindRepr Name = (1, 0)
|
|
||||||
kindRepr Symbol = (2, 0)
|
|
||||||
|
|
||||||
export Eq Kind where (==) = (==) `on` kindRepr
|
|
||||||
export Ord Kind where compare = compare `on` kindRepr
|
|
||||||
|
|
||||||
export
|
|
||||||
Show Kind where
|
|
||||||
show (P p) = show p
|
|
||||||
show Name = "Name"
|
|
||||||
show Symbol = "Symbol"
|
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
|
@ -6,8 +6,11 @@ import Quox.Pretty
|
||||||
|
|
||||||
import Decidable.Equality
|
import Decidable.Equality
|
||||||
import Control.Function
|
import Control.Function
|
||||||
|
import Generics.Derive
|
||||||
|
|
||||||
%default total
|
%default total
|
||||||
|
%language ElabReflection
|
||||||
|
%hide SOP.from; %hide SOP.to
|
||||||
|
|
||||||
|
|
||||||
public export
|
public export
|
||||||
|
@ -17,11 +20,7 @@ data DimConst = Zero | One
|
||||||
private DCRepr : Type
|
private DCRepr : Type
|
||||||
DCRepr = Nat
|
DCRepr = Nat
|
||||||
|
|
||||||
private %inline dcrepr : DimConst -> DCRepr
|
%runElab derive "DimConst" [Generic, Meta, Eq, Ord, DecEq, Show]
|
||||||
dcrepr e = case e of Zero => 0; One => 1
|
|
||||||
|
|
||||||
export Eq DimConst where (==) = (==) `on` dcrepr
|
|
||||||
export Ord DimConst where compare = compare `on` dcrepr
|
|
||||||
|
|
||||||
|
|
||||||
public export
|
public export
|
||||||
|
@ -30,11 +29,10 @@ data Dim : Nat -> Type where
|
||||||
B : Var d -> Dim d
|
B : Var d -> Dim d
|
||||||
%name Dim.Dim p, q
|
%name Dim.Dim p, q
|
||||||
|
|
||||||
private DRepr : Type
|
private %inline
|
||||||
DRepr = Nat
|
drepr : Dim n -> Either DimConst (Var n)
|
||||||
|
drepr (K k) = Left k
|
||||||
private %inline drepr : Dim n -> DRepr
|
drepr (B x) = Right x
|
||||||
drepr p = case p of K i => dcrepr i; B i => 2 + i.nat
|
|
||||||
|
|
||||||
export Eq (Dim n) where (==) = (==) `on` drepr
|
export Eq (Dim n) where (==) = (==) `on` drepr
|
||||||
export Ord (Dim n) where compare = compare `on` drepr
|
export Ord (Dim n) where compare = compare `on` drepr
|
||||||
|
@ -86,8 +84,8 @@ export Uninhabited (One = Zero) where uninhabited _ impossible
|
||||||
export Uninhabited (B i = K e) where uninhabited _ impossible
|
export Uninhabited (B i = K e) where uninhabited _ impossible
|
||||||
export Uninhabited (K e = B i) where uninhabited _ impossible
|
export Uninhabited (K e = B i) where uninhabited _ impossible
|
||||||
|
|
||||||
public export %inline Injective B where injective Refl = Refl
|
public export %inline Injective Dim.B where injective Refl = Refl
|
||||||
public export %inline Injective K where injective Refl = Refl
|
public export %inline Injective Dim.K where injective Refl = Refl
|
||||||
|
|
||||||
public export
|
public export
|
||||||
DecEq DimConst where
|
DecEq DimConst where
|
||||||
|
|
|
@ -3,22 +3,17 @@ module Quox.Syntax.Qty
|
||||||
import Quox.Pretty
|
import Quox.Pretty
|
||||||
|
|
||||||
import Data.Fin
|
import Data.Fin
|
||||||
|
import Generics.Derive
|
||||||
|
|
||||||
%default total
|
%default total
|
||||||
|
%language ElabReflection
|
||||||
|
|
||||||
|
|
||||||
public export
|
public export
|
||||||
data Qty = Zero | One | Any
|
data Qty = Zero | One | Any
|
||||||
%name Qty.Qty pi, rh
|
%name Qty.Qty pi, rh
|
||||||
|
|
||||||
private Repr : Type
|
%runElab derive "Qty" [Generic, Meta, Eq, Ord, DecEq, Show]
|
||||||
Repr = Fin 3
|
|
||||||
|
|
||||||
private %inline repr : Qty -> Repr
|
|
||||||
repr pi = case pi of Zero => 0; One => 1; Any => 2
|
|
||||||
|
|
||||||
export Eq Qty where (==) = (==) `on` repr
|
|
||||||
export Ord Qty where compare = compare `on` repr
|
|
||||||
|
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
|
@ -3,8 +3,10 @@ module Quox.Syntax.Universe
|
||||||
import Quox.Pretty
|
import Quox.Pretty
|
||||||
|
|
||||||
import Data.Fin
|
import Data.Fin
|
||||||
|
import Generics.Derive
|
||||||
|
|
||||||
%default total
|
%default total
|
||||||
|
%language ElabReflection
|
||||||
|
|
||||||
|
|
||||||
||| `UAny` doesn't show up in programs, but when checking something is
|
||| `UAny` doesn't show up in programs, but when checking something is
|
||||||
|
@ -13,14 +15,7 @@ public export
|
||||||
data Universe = U Nat | UAny
|
data Universe = U Nat | UAny
|
||||||
%name Universe l
|
%name Universe l
|
||||||
|
|
||||||
private Repr : Type
|
%runElab derive "Universe" [Generic, Meta, Eq, Ord, DecEq, Show]
|
||||||
Repr = (Fin 2, Nat)
|
|
||||||
|
|
||||||
private %inline repr : Universe -> Repr
|
|
||||||
repr u = case u of U i => (0, i); UAny => (1, 0)
|
|
||||||
|
|
||||||
export Eq Universe where (==) = (==) `on` repr
|
|
||||||
export Ord Universe where compare = compare `on` repr
|
|
||||||
|
|
||||||
export
|
export
|
||||||
PrettyHL Universe where
|
PrettyHL Universe where
|
||||||
|
|
Loading…
Reference in a new issue