{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeData #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Type.Nat (
type Nat (..),
type (+),
type Pred,
type Pos,
type (<=),
) where
import Data.Kind (Constraint)
type data Nat = Z | S Nat
type (+) :: Nat -> Nat -> Nat
type family (+) n m where
Z + m = m
S n + m = S (n + m)
type Pred :: Nat -> Nat
type family Pred n where
Pred (S n) = n
type Pos :: Nat -> Constraint
type Pos (n :: Nat) = n ~ S (Pred n)
type (<=) :: Nat -> Nat -> Bool
type family (<=) n m where
Z <= m = 'True
S n <= Z = 'False
S n <= S m = n <= m