quox/src/Quox/Syntax/Dim.idr

73 lines
1.4 KiB
Idris
Raw Normal View History

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
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
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
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
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
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
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
export FromVar Dim where fromVar = B
2021-07-20 16:05:19 -04:00
2021-12-23 13:01:39 -05:00
export
CanShift Dim where
K e // _ = K e
B i // by = B (i // by)
2021-07-20 16:05:19 -04:00
export
CanSubst Dim Dim where
K e // _ = K e
B i // th = th !! i