{-# language DataKinds #-}
{-# language ExplicitNamespaces #-}
{-# language GADTs #-}
{-# language KindSignatures #-}
{-# language RankNTypes #-}
{-# language TypeOperators #-}
module Arithmetic.Types
( Nat
, WithNat(..)
, Difference(..)
, Fin(..)
, type (<)
, type (<=)
, type (:=:)
) where
import Arithmetic.Unsafe (Nat(getNat), type (<=))
import Arithmetic.Unsafe (type (<), type (:=:))
import Data.Kind (type Type)
import GHC.TypeNats (type (+))
import qualified GHC.TypeNats as GHC
data WithNat :: (GHC.Nat -> Type) -> Type where
WithNat ::
{-# UNPACK #-} !(Nat n)
-> f n
-> WithNat f
data Fin :: GHC.Nat -> Type where
Fin :: forall m n.
{ index :: !(Nat m)
, proof :: !(m < n)
} -> Fin n
data Difference :: GHC.Nat -> GHC.Nat -> Type where
Difference :: forall a b c. Nat c -> (c + b :=: a) -> Difference a b
instance Show (Fin n) where
showsPrec p (Fin i _) = showString "Fin " . showsPrec p (getNat i)
instance Eq (Fin n) where
Fin x _ == Fin y _ = getNat x == getNat y
instance Ord (Fin n) where
Fin x _ `compare` Fin y _ = compare (getNat x) (getNat y)