quox/lib/Quox/Syntax/Qty.idr

85 lines
1.6 KiB
Idris
Raw Normal View History

2021-07-20 16:05:19 -04:00
module Quox.Syntax.Qty
import Quox.Pretty
import Data.Fin
2022-05-02 16:40:28 -04:00
import Generics.Derive
2021-07-20 16:05:19 -04:00
2022-05-02 16:38:37 -04:00
%default total
2022-05-02 16:40:28 -04:00
%language ElabReflection
2022-05-02 16:38:37 -04:00
2021-07-20 16:05:19 -04:00
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
2022-05-02 16:40:28 -04:00
%runElab derive "Qty" [Generic, Meta, Eq, Ord, DecEq, Show]
2021-07-20 16:05:19 -04:00
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
private
commas : List (Doc HL) -> List (Doc HL)
commas [] = []
commas [x] = [x]
commas (x::xs) = (x <+> hl Delim ",") :: commas xs
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 ((hl Delim "@" <++>) . align . sep . commas) . traverse pretty0M
2021-07-20 16:05:19 -04:00
public export
2021-09-09 17:51:45 -04:00
plus : Qty -> Qty -> Qty
plus Zero rh = rh
plus pi Zero = pi
plus _ _ = Any
2021-07-20 16:05:19 -04:00
public export
2021-09-09 17:51:45 -04:00
times : Qty -> Qty -> Qty
times Zero _ = Zero
times _ Zero = Zero
times One rh = rh
times pi One = pi
times Any Any = Any
2021-07-20 16:05:19 -04:00
infix 6 <=.
public export
2021-09-09 17:51:45 -04:00
compat : Qty -> Qty -> Bool
compat pi rh = rh == Any || pi == rh
public export
interface IsQty q where
zero, one : q
(+), (*) : q -> q -> q
(<=.) : q -> q -> Bool
public export
IsQty Qty where
zero = Zero; one = One
(+) = plus; (*) = times
(<=.) = compat
public export
data IsSubj : Qty -> Type where
SZero : IsSubj Zero
SOne : IsSubj One
2022-08-22 04:07:46 -04:00
export Uninhabited (IsSubj Any) where uninhabited _ impossible
public export
data IsGlobal : Qty -> Type where
GZero : IsGlobal Zero
GAny : IsGlobal Any
2022-08-22 04:07:46 -04:00
export Uninhabited (IsGlobal One) where uninhabited _ impossible