quox/lib/Quox/Syntax/Qty/Three.idr

138 lines
2.8 KiB
Idris
Raw Normal View History

2023-01-08 14:44:25 -05:00
module Quox.Syntax.Qty.Three
import Quox.Pretty
import public Quox.Syntax.Qty
2023-03-02 13:52:32 -05:00
import Derive.Prelude
2023-01-08 14:44:25 -05:00
%default total
%language ElabReflection
public export
data Three = Zero | One | Any
%name Three pi, rh
2023-03-02 13:52:32 -05:00
%runElab derive "Three" [Eq, Ord, Show]
2023-01-08 14:44:25 -05:00
export
PrettyHL Three where
prettyM pi = hl Qty <$>
case pi of
2023-03-15 10:54:51 -04:00
Zero => pure "0"
One => pure "1"
Any => ifUnicode "ω" "#"
2023-01-08 14:44:25 -05:00
2023-03-02 13:52:32 -05:00
public export
DecEq Three where
decEq Zero Zero = Yes Refl
decEq Zero One = No $ \case _ impossible
decEq Zero Any = No $ \case _ impossible
decEq One Zero = No $ \case _ impossible
decEq One One = Yes Refl
decEq One Any = No $ \case _ impossible
decEq Any Zero = No $ \case _ impossible
decEq Any One = No $ \case _ impossible
decEq Any Any = Yes Refl
2023-01-08 14:44:25 -05:00
public export
plus : Three -> Three -> Three
plus Zero rh = rh
plus pi Zero = pi
plus _ _ = Any
public export
times : Three -> Three -> Three
times Zero _ = Zero
times _ Zero = Zero
times One rh = rh
times pi One = pi
times Any Any = Any
public export
lub3 : Three -> Three -> Maybe Three
lub3 p q =
if p == Any || q == Any then Just Any
else if p == q then Just p
else Nothing
2023-01-08 14:44:25 -05:00
public export
2023-01-09 17:43:23 -05:00
data Compat3 : Rel Three where
CmpRefl : Compat3 rh rh
CmpAny : Compat3 rh Any
2023-01-08 14:44:25 -05:00
public export
2023-01-09 17:43:23 -05:00
compat3 : Dec2 Compat3
2023-01-09 17:45:21 -05:00
compat3 pi rh with (decEq pi rh) | (decEq rh Any)
compat3 pi pi | Yes Refl | _ = Yes CmpRefl
compat3 pi Any | No _ | Yes Refl = Yes CmpAny
compat3 pi rh | No ne | No na =
No $ \case CmpRefl => ne Refl; CmpAny => na Refl
2023-01-08 14:44:25 -05:00
public export
2023-01-09 17:43:23 -05:00
data IsSubj3 : Pred Three where
2023-01-08 14:44:25 -05:00
SZero : IsSubj3 Zero
SOne : IsSubj3 One
public export
2023-01-09 17:43:23 -05:00
isSubj3 : Dec1 IsSubj3
2023-01-08 14:44:25 -05:00
isSubj3 Zero = Yes SZero
isSubj3 One = Yes SOne
isSubj3 Any = No $ \case _ impossible
2023-01-09 17:43:55 -05:00
public export
timesSubj3 : forall pi, rh. IsSubj3 pi -> IsSubj3 rh -> IsSubj3 (times pi rh)
timesSubj3 SZero SZero = SZero
timesSubj3 SZero SOne = SZero
timesSubj3 SOne SZero = SZero
timesSubj3 SOne SOne = SOne
2023-01-08 14:44:25 -05:00
public export
2023-01-09 17:43:23 -05:00
data IsGlobal3 : Pred Three where
2023-01-08 14:44:25 -05:00
GZero : IsGlobal3 Zero
GAny : IsGlobal3 Any
2023-03-15 10:54:51 -04:00
public export
2023-01-09 17:43:23 -05:00
isGlobal3 : Dec1 IsGlobal3
2023-01-08 14:44:25 -05:00
isGlobal3 Zero = Yes GZero
isGlobal3 One = No $ \case _ impossible
isGlobal3 Any = Yes GAny
public export
IsQty Three where
zero = Zero
one = One
(+) = plus
(*) = times
lub = lub3
2023-01-08 14:44:25 -05:00
IsZero = Equal Zero
isZero = decEq Zero
zeroIsZero = Refl
Compat = Compat3
compat = compat3
IsSubj = IsSubj3
isSubj = isSubj3
zeroIsSubj = \Refl => SZero
2023-01-08 14:44:25 -05:00
oneIsSubj = SOne
2023-01-09 17:43:55 -05:00
timesSubj = timesSubj3
2023-01-08 14:44:25 -05:00
IsGlobal = IsGlobal3
isGlobal = isGlobal3
zeroIsGlobal = \Refl => GZero
2023-01-08 14:44:25 -05:00
prettySuffix = pretty0M
2023-01-08 14:44:25 -05:00
export Uninhabited (IsGlobal3 One) where uninhabited _ impossible
export Uninhabited (IsSubj3 Any) where uninhabited _ impossible