Raise the index by m and weaken the bound by m, adding
m to the left-hand side of n.
Modulenatural-arithmetic-0.2.1.0Haskell2010
Arithmetic.Fin
- 37 values
- Packagenatural-arithmetic-0.2.1.0
- Exports37
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFin.hs
Modification
8 declarationsRaise the index by m and weaken the bound by m, adding
m to the right-hand side of n.
Weaken the bound, replacing it by another number greater than or equal to itself. This does not change the index.
Weaken the bound by m, adding it to the left-hand side of
the existing bound. This does not change the index.
Weaken the bound by m, adding it to the right-hand side of
the existing bound. This does not change the index.
Return the successor of the Fin or return nothing if the argument is the greatest inhabitant.
Variant of succ for unlifted finite numbers.
Traverse
17 declarationsThese use the terms ascend and descend rather than the
more popular l (left) and r (right) that pervade the Haskell
ecosystem. The general rule is that ascending functions pair
the initial accumulator with zero with descending functions
pair the initial accumulator with the last index.
Fold over the numbers bounded by n in ascending order. This
is lazy in the accumulator.
ascend 4 z f = f 3 (f 2 (f 1 (f 0 z)))Strict fold over the numbers bounded by n in ascending
order. For convenince, this differs from foldl' in the
order of the parameters.
ascend' 4 z f = f 3 (f 2 (f 1 (f 0 z)))ascendFrom' Generalization of ascend' that lets the caller pick the starting index:
ascend' === ascendFrom' 0ascendFrom'# Variant of ascendFrom' with unboxed arguments.
ascendM Strict monadic left fold over the numbers bounded by n
in ascending order. Roughly:
ascendM 4 z0 f =
f 0 z0 >>= \z1 ->
f 1 z1 >>= \z2 ->
f 2 z2 >>= \z3 ->
f 3 z3ascendM# Variant of ascendM that takes an unboxed Nat and provides
an unboxed Fin to the callback.
Monadic traversal of the numbers bounded by n
in ascending order.
ascendM_ 4 f = f 0 *> f 1 *> f 2 *> f 3Variant of ascendM_ that takes an unboxed Nat and provides
an unboxed Fin to the callback.
Fold over the numbers bounded by n in descending
order. This is lazy in the accumulator. For convenince,
this differs from foldr in the order of the parameters.
descend 4 z f = f 0 (f 1 (f 2 (f 3 z)))Fold over the numbers bounded by n in descending
order. This is strict in the accumulator. For convenince,
this differs from foldr' in the order of the parameters.
descend 4 z f = f 0 (f 1 (f 2 (f 3 z)))Strict monadic left fold over the numbers bounded by n
in descending order. Roughly:
descendM 4 z f =
f 3 z0 >>= \z1 ->
f 2 z1 >>= \z2 ->
f 1 z2 >>= \z3 ->
f 0 z3Monadic traversal of the numbers bounded by n
in descending order.
descendM_ 4 f = f 3 *> f 2 *> f 1 *> f 0Generate all values of a finite set in ascending order.
ascending (Nat.constant @3)[Fin 0,Fin 1,Fin 2]
Generate all values of a finite set in descending order.
descending (Nat.constant @3)[Fin 2,Fin 1,Fin 0]
Generate len values starting from off in ascending order.
ascendingSlice (Nat.constant @2) (Nat.constant @3) (Lte.constant @_ @6)[Fin 2,Fin 3,Fin 4]
Generate len values starting from 'off + len - 1' in descending order.
descendingSlice (Nat.constant @2) (Nat.constant @3) (Lt.constant @6)[Fin 4,Fin 3,Fin 2]
Absurdities
1 declarationA finite set of no values is impossible.
Demote
2 declarationsExtract the Int from a 'Fin n'. This is intended to be used at a boundary where a safe interface meets the unsafe primitives on top of which it is built.
Deconstruct
2 declarationsConsume the natural number and the proof in the Fin.
Variant of with for unboxed argument and result types.
Construct
5 declarationsThis crashes if n = 0. Divides i by n and takes
the remainder.
This crashes if n = 0. Divides i by n and takes
the remainder.
Convert an Int to a finite number, testing that it is less than the upper bound. This crashes with an uncatchable exception when given a negative number.
Unboxed variant of fromInt.