quox/src/Quox/Syntax/Qty.idr

55 lines
997 B
Idris
Raw Normal View History

2021-07-20 16:05:19 -04:00
module Quox.Syntax.Qty
import Quox.Pretty
import Data.Fin
public export
2021-09-03 11:56:04 -04:00
data Qty = Zero | One | Any
2021-07-20 16:05:19 -04:00
%name Qty.Qty pi, rh
private Repr : Type
Repr = Fin 3
private %inline repr : Qty -> Repr
2021-09-03 11:56:04 -04:00
repr pi = case pi of Zero => 0; One => 1; Any => 2
2021-07-20 16:05:19 -04:00
export Eq Qty where (==) = (==) `on` repr
export Ord Qty where compare = compare `on` repr
export
PrettyHL Qty where
prettyM pi = hl Qty <$>
case pi of
Zero => ifUnicode "𝟬" "0"
One => ifUnicode "𝟭" "1"
2021-09-03 11:56:04 -04:00
Any => ifUnicode "𝛚" "*"
2021-07-20 16:05:19 -04:00
export %inline
prettyQtyBinds : Pretty.HasEnv m => List Qty -> m (Doc HL)
2021-07-20 16:05:19 -04:00
prettyQtyBinds =
map (align . sep) .
traverse (\pi => [|pretty0M pi <++> pure (hl Delim "|")|])
public export
(+) : Qty -> Qty -> Qty
Zero + rh = rh
pi + Zero = pi
2021-09-03 11:56:04 -04:00
_ + _ = Any
2021-07-20 16:05:19 -04:00
public export
(*) : Qty -> Qty -> Qty
Zero * _ = Zero
_ * Zero = Zero
One * rh = rh
pi * One = pi
2021-09-03 11:56:04 -04:00
Any * Any = Any
2021-07-20 16:05:19 -04:00
infix 6 <=.
public export
(<=.) : Qty -> Qty -> Bool
2021-09-03 11:56:04 -04:00
pi <=. rh = rh == Any || pi == rh