{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Type.Nat.LE.ReflStep (
LEProof (..),
fromZeroSucc,
toZeroSucc,
decideLE,
leZero,
leSucc,
leRefl,
leStep,
leAsym,
leTrans,
leSwap,
leSwap',
leStepL,
lePred,
proofZeroLEZero,
) where
import Data.Type.Dec (Dec (..), Decidable (..), Neg)
import Data.Typeable (Typeable)
import Data.Void (absurd)
import qualified Control.Category as C
import Data.Type.Nat
import qualified Data.Type.Nat.LE as ZeroSucc
import TrustworthyCompat
data LEProof n m where
LERefl :: LEProof n n
LEStep :: LEProof n m -> LEProof n ('S m)
deriving (Typeable)
deriving instance Show (LEProof n m)
instance Eq (LEProof n m) where
LEProof n m
_ == :: LEProof n m -> LEProof n m -> Bool
== LEProof n m
_ = Bool
True
instance Ord (LEProof n m) where
compare :: LEProof n m -> LEProof n m -> Ordering
compare LEProof n m
_ LEProof n m
_ = Ordering
EQ
instance C.Category LEProof where
id :: LEProof a a
id = LEProof a a
forall (a :: Nat). LEProof a a
leRefl
. :: LEProof b c -> LEProof a b -> LEProof a c
(.) = (LEProof a b -> LEProof b c -> LEProof a c)
-> LEProof b c -> LEProof a b -> LEProof a c
forall a b c. (a -> b -> c) -> b -> a -> c
flip LEProof a b -> LEProof b c -> LEProof a c
forall (n :: Nat) (m :: Nat) (p :: Nat).
LEProof n m -> LEProof m p -> LEProof n p
leTrans
fromZeroSucc :: forall n m. SNatI m => ZeroSucc.LEProof n m -> LEProof n m
fromZeroSucc :: LEProof n m -> LEProof n m
fromZeroSucc LEProof n m
ZeroSucc.LEZero = LEProof n m
forall (n :: Nat). SNatI n => LEProof 'Z n
leZero
fromZeroSucc (ZeroSucc.LESucc LEProof n m
p) = case SNat m
forall (n :: Nat). SNatI n => SNat n
snat :: SNat m of
SNat m
SS -> LEProof n m -> LEProof ('S n) ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc (LEProof n m -> LEProof n m
forall (n :: Nat) (m :: Nat). SNatI m => LEProof n m -> LEProof n m
fromZeroSucc LEProof n m
p)
toZeroSucc :: SNatI n => LEProof n m -> ZeroSucc.LEProof n m
toZeroSucc :: LEProof n m -> LEProof n m
toZeroSucc LEProof n m
LERefl = LEProof n m
forall (n :: Nat). SNatI n => LEProof n n
ZeroSucc.leRefl
toZeroSucc (LEStep LEProof n m
p) = LEProof n m -> LEProof n ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
ZeroSucc.leStep (LEProof n m -> LEProof n m
forall (n :: Nat) (m :: Nat). SNatI n => LEProof n m -> LEProof n m
toZeroSucc LEProof n m
p)
leZero :: forall n. SNatI n => LEProof 'Z n
leZero :: LEProof 'Z n
leZero = case SNat n
forall (n :: Nat). SNatI n => SNat n
snat :: SNat n of
SNat n
SZ -> LEProof 'Z n
forall (a :: Nat). LEProof a a
LERefl
SNat n
SS -> LEProof 'Z n -> LEProof 'Z ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep LEProof 'Z n
forall (n :: Nat). SNatI n => LEProof 'Z n
leZero
leSucc :: LEProof n m -> LEProof ('S n) ('S m)
leSucc :: LEProof n m -> LEProof ('S n) ('S m)
leSucc LEProof n m
LERefl = LEProof ('S n) ('S m)
forall (a :: Nat). LEProof a a
LERefl
leSucc (LEStep LEProof n m
p) = LEProof ('S n) ('S m) -> LEProof ('S n) ('S ('S m))
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep (LEProof n m -> LEProof ('S n) ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc LEProof n m
p)
lePred :: LEProof ('S n) ('S m) -> LEProof n m
lePred :: LEProof ('S n) ('S m) -> LEProof n m
lePred LEProof ('S n) ('S m)
LERefl = LEProof n m
forall (a :: Nat). LEProof a a
LERefl
lePred (LEStep LEProof ('S n) m
LERefl) = LEProof n n -> LEProof n ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep LEProof n n
forall (a :: Nat). LEProof a a
LERefl
lePred (LEStep (LEStep LEProof ('S n) m
q)) = LEProof n m -> LEProof n ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep (LEProof ('S n) m -> LEProof n m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof ('S n) m
q)
leRefl :: LEProof n n
leRefl :: LEProof n n
leRefl = LEProof n n
forall (a :: Nat). LEProof a a
LERefl
leStep :: LEProof n m -> LEProof n ('S m)
leStep :: LEProof n m -> LEProof n ('S m)
leStep = LEProof n m -> LEProof n ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep
leStepL :: LEProof ('S n) m -> LEProof n m
leStepL :: LEProof ('S n) m -> LEProof n m
leStepL LEProof ('S n) m
LERefl = LEProof n n -> LEProof n ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep LEProof n n
forall (a :: Nat). LEProof a a
LERefl
leStepL (LEStep LEProof ('S n) m
p) = LEProof n m -> LEProof n ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep (LEProof ('S n) m -> LEProof n m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof ('S n) m
p)
leAsym :: LEProof n m -> LEProof m n -> n :~: m
leAsym :: LEProof n m -> LEProof m n -> (:~:) @Nat n m
leAsym LEProof n m
LERefl LEProof m n
_ = (:~:) @Nat n m
forall k (a :: k). (:~:) @k a a
Refl
leAsym LEProof n m
_ LEProof m n
LERefl = (:~:) @Nat n m
forall k (a :: k). (:~:) @k a a
Refl
leAsym (LEStep LEProof n m
p) (LEStep LEProof m m
q) = case LEProof m m -> LEProof m m -> (:~:) @Nat m m
forall (n :: Nat) (m :: Nat).
LEProof n m -> LEProof m n -> (:~:) @Nat n m
leAsym (LEProof ('S m) m -> LEProof m m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof n m
LEProof ('S m) m
p) (LEProof ('S m) m -> LEProof m m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof m m
LEProof ('S m) m
q) of
(:~:) @Nat m m
Refl -> (:~:) @Nat n m
forall k (a :: k). (:~:) @k a a
Refl
leTrans :: LEProof n m -> LEProof m p -> LEProof n p
leTrans :: LEProof n m -> LEProof m p -> LEProof n p
leTrans LEProof n m
p LEProof m p
LERefl = LEProof n m
LEProof n p
p
leTrans LEProof n m
p (LEStep LEProof m m
q) = LEProof n m -> LEProof n ('S m)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof n ('S m)
LEStep (LEProof n m -> LEProof n ('S m))
-> LEProof n m -> LEProof n ('S m)
forall a b. (a -> b) -> a -> b
$ LEProof n m -> LEProof m m -> LEProof n m
forall (n :: Nat) (m :: Nat) (p :: Nat).
LEProof n m -> LEProof m p -> LEProof n p
leTrans LEProof n m
p LEProof m m
q
leSwap :: forall n m. (SNatI n, SNatI m) => Neg (LEProof n m) -> LEProof ('S m) n
leSwap :: Neg (LEProof n m) -> LEProof ('S m) n
leSwap Neg (LEProof n m)
np = case (SNat m
forall (n :: Nat). SNatI n => SNat n
snat :: SNat m, SNat n
forall (n :: Nat). SNatI n => SNat n
snat :: SNat n) of
(SNat m
_, SNat n
SZ) -> Void -> LEProof ('S m) n
forall a. Void -> a
absurd (Neg (LEProof n m)
np LEProof n m
forall (n :: Nat). SNatI n => LEProof 'Z n
leZero)
(SNat m
SZ, SNat n
SS) -> LEProof 'Z n -> LEProof ('S 'Z) ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc LEProof 'Z n
forall (n :: Nat). SNatI n => LEProof 'Z n
leZero
(SNat m
SS, SNat n
SS) -> LEProof ('S n) n -> LEProof ('S ('S n)) ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc (LEProof ('S n) n -> LEProof ('S ('S n)) ('S n))
-> LEProof ('S n) n -> LEProof ('S ('S n)) ('S n)
forall a b. (a -> b) -> a -> b
$ Neg (LEProof n n) -> LEProof ('S n) n
forall (n :: Nat) (m :: Nat).
(SNatI n, SNatI m) =>
Neg (LEProof n m) -> LEProof ('S m) n
leSwap (Neg (LEProof n n) -> LEProof ('S n) n)
-> Neg (LEProof n n) -> LEProof ('S n) n
forall a b. (a -> b) -> a -> b
$ \LEProof n n
p -> Neg (LEProof n m)
np Neg (LEProof n m) -> Neg (LEProof n m)
forall a b. (a -> b) -> a -> b
$ LEProof n n -> LEProof ('S n) ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc LEProof n n
p
leSwap' :: LEProof n m -> LEProof ('S m) n -> void
leSwap' :: LEProof n m -> LEProof ('S m) n -> void
leSwap' LEProof n m
p LEProof ('S m) n
LERefl = case LEProof n m
p of LEStep LEProof n m
p' -> LEProof ('S m) m -> LEProof ('S m) ('S m) -> void
forall (n :: Nat) (m :: Nat) void.
LEProof n m -> LEProof ('S m) n -> void
leSwap' (LEProof ('S ('S m)) m -> LEProof ('S m) m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof n m
LEProof ('S ('S m)) m
p') LEProof ('S m) ('S m)
forall (a :: Nat). LEProof a a
LERefl
leSwap' LEProof n m
p (LEStep LEProof ('S m) m
q) = LEProof m m -> LEProof ('S m) m -> void
forall (n :: Nat) (m :: Nat) void.
LEProof n m -> LEProof ('S m) n -> void
leSwap' (LEProof ('S m) m -> LEProof m m
forall (n :: Nat) (m :: Nat). LEProof ('S n) m -> LEProof n m
leStepL LEProof n m
LEProof ('S m) m
p) LEProof ('S m) m
q
decideLE :: forall n m. (SNatI n, SNatI m) => Dec (LEProof n m)
decideLE :: Dec (LEProof n m)
decideLE = case SNat n
forall (n :: Nat). SNatI n => SNat n
snat :: SNat n of
SNat n
SZ -> LEProof 'Z m -> Dec (LEProof 'Z m)
forall a. a -> Dec a
Yes LEProof 'Z m
forall (n :: Nat). SNatI n => LEProof 'Z n
leZero
SNat n
SS -> Dec (LEProof n m)
forall (n' :: Nat) (m' :: Nat).
(SNatI n', SNatI m') =>
Dec (LEProof ('S n') m')
caseSnm
where
caseSnm :: forall n' m'. (SNatI n', SNatI m') => Dec (LEProof ('S n') m')
caseSnm :: Dec (LEProof ('S n') m')
caseSnm = case SNat m'
forall (n :: Nat). SNatI n => SNat n
snat :: SNat m' of
SNat m'
SZ -> Neg (LEProof ('S n') m') -> Dec (LEProof ('S n') m')
forall a. Neg a -> Dec a
No (Neg (LEProof ('S n') m') -> Dec (LEProof ('S n') m'))
-> Neg (LEProof ('S n') m') -> Dec (LEProof ('S n') m')
forall a b. (a -> b) -> a -> b
$ \LEProof ('S n') m'
p -> case LEProof ('S n') m'
p of {}
SNat m'
SS -> case Dec (LEProof n' n)
forall (n :: Nat) (m :: Nat).
(SNatI n, SNatI m) =>
Dec (LEProof n m)
decideLE of
Yes LEProof n' n
p -> LEProof ('S n') ('S n) -> Dec (LEProof ('S n') ('S n))
forall a. a -> Dec a
Yes (LEProof n' n -> LEProof ('S n') ('S n)
forall (n :: Nat) (m :: Nat). LEProof n m -> LEProof ('S n) ('S m)
leSucc LEProof n' n
p)
No Neg (LEProof n' n)
p -> Neg (LEProof ('S n') ('S n)) -> Dec (LEProof ('S n') ('S n))
forall a. Neg a -> Dec a
No (Neg (LEProof ('S n') ('S n)) -> Dec (LEProof ('S n') ('S n)))
-> Neg (LEProof ('S n') ('S n)) -> Dec (LEProof ('S n') ('S n))
forall a b. (a -> b) -> a -> b
$ \LEProof ('S n') ('S n)
p' -> Neg (LEProof n' n)
p (LEProof ('S n') ('S n) -> LEProof n' n
forall (n :: Nat) (m :: Nat). LEProof ('S n) ('S m) -> LEProof n m
lePred LEProof ('S n') ('S n)
p')
instance (SNatI n, SNatI m) => Decidable (LEProof n m) where
decide :: Dec (LEProof n m)
decide = Dec (LEProof n m)
forall (n :: Nat) (m :: Nat).
(SNatI n, SNatI m) =>
Dec (LEProof n m)
decideLE
proofZeroLEZero :: LEProof n 'Z -> n :~: 'Z
proofZeroLEZero :: LEProof n 'Z -> (:~:) @Nat n 'Z
proofZeroLEZero LEProof n 'Z
LERefl = (:~:) @Nat n 'Z
forall k (a :: k). (:~:) @k a a
Refl