2021-07-20 16:05:19 -04:00
|
|
|
|
module Quox.Syntax.Dim
|
|
|
|
|
|
|
|
|
|
import Quox.Syntax.Var
|
|
|
|
|
import Quox.Syntax.Subst
|
|
|
|
|
import Quox.Pretty
|
|
|
|
|
|
|
|
|
|
%default total
|
|
|
|
|
|
|
|
|
|
|
2021-12-23 09:52:56 -05:00
|
|
|
|
public export
|
|
|
|
|
data DimConst = Zero | One
|
|
|
|
|
%name DimConst e
|
|
|
|
|
|
|
|
|
|
private DCRepr : Type
|
|
|
|
|
DCRepr = Nat
|
|
|
|
|
|
|
|
|
|
private %inline dcrepr : DimConst -> DCRepr
|
|
|
|
|
dcrepr e = case e of Zero => 0; One => 1
|
|
|
|
|
|
|
|
|
|
export Eq DimConst where (==) = (==) `on` dcrepr
|
|
|
|
|
export Ord DimConst where compare = compare `on` dcrepr
|
|
|
|
|
|
|
|
|
|
|
2021-07-20 16:05:19 -04:00
|
|
|
|
public export
|
|
|
|
|
data Dim : Nat -> Type where
|
2021-12-23 09:52:56 -05:00
|
|
|
|
K : DimConst -> Dim d
|
|
|
|
|
B : Var d -> Dim d
|
2021-07-20 16:05:19 -04:00
|
|
|
|
%name Dim.Dim p, q
|
|
|
|
|
|
|
|
|
|
private DRepr : Type
|
|
|
|
|
DRepr = Nat
|
|
|
|
|
|
|
|
|
|
private %inline drepr : Dim n -> DRepr
|
2021-12-23 09:52:56 -05:00
|
|
|
|
drepr p = case p of K i => dcrepr i; B i => 2 + i.nat
|
2021-07-20 16:05:19 -04:00
|
|
|
|
|
|
|
|
|
export Eq (Dim n) where (==) = (==) `on` drepr
|
|
|
|
|
export Ord (Dim n) where compare = compare `on` drepr
|
|
|
|
|
|
2021-12-23 09:52:56 -05:00
|
|
|
|
export
|
|
|
|
|
PrettyHL DimConst where
|
|
|
|
|
prettyM Zero = hl Dim <$> ifUnicode "𝟬" "0"
|
|
|
|
|
prettyM One = hl Dim <$> ifUnicode "𝟭" "1"
|
|
|
|
|
|
2021-07-20 16:05:19 -04:00
|
|
|
|
export
|
|
|
|
|
PrettyHL (Dim n) where
|
2021-12-23 09:52:56 -05:00
|
|
|
|
prettyM (K e) = prettyM e
|
|
|
|
|
prettyM (B i) = prettyVar DVar DVarErr (!ask).dnames i
|
2021-07-20 16:05:19 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public export
|
2021-09-03 10:34:57 -04:00
|
|
|
|
DSubst : Nat -> Nat -> Type
|
2021-07-20 16:05:19 -04:00
|
|
|
|
DSubst = Subst Dim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export %inline
|
2021-09-03 09:00:16 -04:00
|
|
|
|
prettyDSubst : Pretty.HasEnv m => DSubst from to -> m (Doc HL)
|
2021-07-20 16:05:19 -04:00
|
|
|
|
prettyDSubst th =
|
2021-09-03 10:31:53 -04:00
|
|
|
|
prettySubstM prettyM (!ask).dnames DVar
|
2021-07-20 16:05:19 -04:00
|
|
|
|
!(ifUnicode "⟨" "<") !(ifUnicode "⟩" ">") th
|
|
|
|
|
|
|
|
|
|
|
2021-12-23 09:52:56 -05:00
|
|
|
|
export FromVar Dim where fromVar = B
|
2021-07-20 16:05:19 -04:00
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
CanSubst Dim Dim where
|
2021-12-23 09:52:56 -05:00
|
|
|
|
K e // _ = K e
|
|
|
|
|
B i // th = th !! i
|