51 lines
1.0 KiB
Idris
51 lines
1.0 KiB
Idris
module Quox.Syntax.Dim
|
||
|
||
import Quox.Syntax.Var
|
||
import Quox.Syntax.Subst
|
||
import Quox.Pretty
|
||
|
||
%default total
|
||
|
||
|
||
public export
|
||
data Dim : Nat -> Type where
|
||
DZero, DOne : Dim d
|
||
DBound : Var d -> Dim d
|
||
%name Dim.Dim p, q
|
||
|
||
private DRepr : Type
|
||
DRepr = Nat
|
||
|
||
private %inline drepr : Dim n -> DRepr
|
||
drepr d = case d of DZero => 0; DOne => 1; DBound i => 2 + i.nat
|
||
|
||
export Eq (Dim n) where (==) = (==) `on` drepr
|
||
export Ord (Dim n) where compare = compare `on` drepr
|
||
|
||
export
|
||
PrettyHL (Dim n) where
|
||
prettyM DZero = hl Dim <$> ifUnicode "𝟬" "0"
|
||
prettyM DOne = hl Dim <$> ifUnicode "𝟭" "1"
|
||
prettyM (DBound i) = prettyVar DVar DVarErr (!ask).dnames i
|
||
|
||
|
||
public export
|
||
0 DSubst : Nat -> Nat -> Type
|
||
DSubst = Subst Dim
|
||
|
||
|
||
export %inline
|
||
prettyDSubst : Pretty.HasEnv m => DSubst from to -> m (Doc HL)
|
||
prettyDSubst th =
|
||
prettySubstM prettyM (dnames !ask) DVar
|
||
!(ifUnicode "⟨" "<") !(ifUnicode "⟩" ">") th
|
||
|
||
|
||
export FromVar Dim where fromVar = DBound
|
||
|
||
export
|
||
CanSubst Dim Dim where
|
||
DZero // _ = DZero
|
||
DOne // _ = DOne
|
||
DBound i // th = th !! i
|