dhall-nix-lib/Integer/fold.dhall

21 lines
573 B
Text

let Integer/negative = ./negative.dhall
let Integer/abs = ./abs.dhall
let fold
: Integer →
∀(integer : Type) →
∀(succ : integer → integer) →
∀(negate : integer → integer) →
∀(zero : integer) →
integer
= λ(e : Integer) →
λ(integer : Type) →
λ(succ : integer → integer) →
λ(negate : integer → integer) →
λ(zero : integer) →
let folded = Natural/fold (Integer/abs e) integer succ zero
in if Integer/negative e then negate folded else folded
in fold