Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions libs/prelude/Prelude/Nat.idr
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ mult (S left) right = plus right $ mult left right

||| Convert an Integer to a Nat, mapping negative numbers to 0
fromIntegerNat : Integer -> Nat
fromIntegerNat 0 = Z
fromIntegerNat n =
if (n > 0) then
S (fromIntegerNat (assert_smaller n (n - 1)))
else
Z
fromIntegerNat i =
case (i > 0) of
True => S (fromIntegerNat (assert_smaller i (i - 1)))
False => Z
-- Using if here would cause infinite looping in some cases.
-- This could be fixed by redundantly matching on 0 explicitly, but that would stop
-- fromIntegerNat from reducing in proofs.

||| Convert a Nat to an Integer
toIntegerNat : Nat -> Integer
Expand Down