Copyright | (C) 2015-2016 University of Twente 2017-2018 QBayLogic B.V. |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Extensions |
|
Additional type-level operations on Nat
:
Max
: type-levelmax
Min
: type-levelmin
Div
: type-leveldiv
Mod
: type-levelmod
FLog
: type-level equivalent of integerLogBase# .i.e. the exact integer equivalent to "
"floor
(logBase
x y)CLog
: type-level equivalent of the ceiling of integerLogBase# .i.e. the exact integer equivalent to "
"ceiling
(logBase
x y)Log
: type-level equivalent of integerLogBase# where the operation only reduces when "
"floor
(logBase
b x) ~ceiling
(logBase
b x)GCD
: a type-levelgcd
LCM
: a type-levellcm
A custom solver for the above operations defined is defined in GHC.TypeLits.Extra.Solver as a GHC type-checker plugin. To use the plugin, add the
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Extra.Solver #-}
pragma to the header of your file.
- type family Max (x :: Nat) (y :: Nat) :: Nat where ...
- type family Min (x :: Nat) (y :: Nat) :: Nat where ...
- type family Div (x :: Nat) (y :: Nat) :: Nat where ...
- type family Mod (x :: Nat) (y :: Nat) :: Nat where ...
- type DivMod n d = '(Div n d, Mod n d)
- type DivRU n d = Div (n + (d - 1)) d
- type family FLog (x :: Nat) (y :: Nat) :: Nat where ...
- type family CLog (x :: Nat) (y :: Nat) :: Nat where ...
- type family Log (x :: Nat) (y :: Nat) :: Nat where ...
- type family GCD (x :: Nat) (y :: Nat) :: Nat where ...
- type family LCM (x :: Nat) (y :: Nat) :: Nat where ...
Type-level operations on Nat
Ord
Integral
type family Div (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level div
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
Div x 1 = x |
type family Mod (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level mod
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
Mod x 1 = 0 |
Variants
Logarithm
type family FLog (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level equivalent of integerLogBase#
.i.e. the exact integer equivalent to "
"floor
(logBase
x y)
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
FLog 2 1 = 0 |
type family CLog (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level equivalent of the ceiling of integerLogBase#
.i.e. the exact integer equivalent to "
"ceiling
(logBase
x y)
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
CLog 2 1 = 0 |
Exact logarithm
type family Log (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level equivalent of integerLogBase# where the operation only reduces when:
FLog
b x ~CLog
b x
Additionally, the following property holds for Log
:
(b ^ (Log b x)) ~ x
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
Log 2 1 = 0 |
type family GCD (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level greatest common denominator (GCD).
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
type family LCM (x :: Nat) (y :: Nat) :: Nat where ... Source #
Type-level least common multiple (LCM).
Note that additional equations are provided by the type-checker plugin solver GHC.TypeLits.Extra.Solver.
Orphan instances
(KnownNat x, KnownNat y, (<=) 2 x, (<=) 1 y) => KnownNat2 "GHC.TypeLits.Extra.CLog" x y Source # | |
(KnownNat x, KnownNat y, (<=) 1 y) => KnownNat2 "GHC.TypeLits.Extra.Div" x y Source # | |
(KnownNat x, KnownNat y, (<=) 2 x, (<=) 1 y) => KnownNat2 "GHC.TypeLits.Extra.FLog" x y Source # | |
(KnownNat x, KnownNat y) => KnownNat2 "GHC.TypeLits.Extra.GCD" x y Source # | |
(KnownNat x, KnownNat y) => KnownNat2 "GHC.TypeLits.Extra.LCM" x y Source # | |
(KnownNat x, KnownNat y, (~) Nat (FLog x y) (CLog x y)) => KnownNat2 "GHC.TypeLits.Extra.Log" x y Source # | |
(KnownNat x, KnownNat y) => KnownNat2 "GHC.TypeLits.Extra.Max" x y Source # | |
(KnownNat x, KnownNat y) => KnownNat2 "GHC.TypeLits.Extra.Min" x y Source # | |
(KnownNat x, KnownNat y, (<=) 1 y) => KnownNat2 "GHC.TypeLits.Extra.Mod" x y Source # | |