New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small improvements for Prelude.Natural #719
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5433f8c
Prelude: Add Natural.subtract
sjakobi 001f457
Prelude: Small improvements for the Natural comparison functions
sjakobi 8ab95dc
Update nixops/dhall-haskell.json
sjakobi e794275
Update dhall-haskell again
sjakobi 59b4b47
Fix some assertions
sjakobi ce30add
Merge branch 'master' into sjakobi/prelude-natural-improvements
sjakobi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
{- | ||
`equal` checks if two Naturals are equal. | ||
-} | ||
let lessThanEqual = | ||
./lessThanEqual sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 | ||
? ./lessThanEqual | ||
|
||
let equal | ||
: Natural → Natural → Bool | ||
= λ(a : Natural) | ||
→ λ(b : Natural) | ||
→ Natural/isZero (Natural/subtract a b) | ||
&& Natural/isZero (Natural/subtract b a) | ||
= λ(a : Natural) → λ(b : Natural) → lessThanEqual a b && lessThanEqual b a | ||
|
||
let example0 = assert : equal 5 5 ≡ True | ||
|
||
let example1 = assert : equal 5 6 ≡ False | ||
|
||
let property0 = λ(n : Natural) → assert : equal n n ≡ True | ||
sjakobi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
in equal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
{- | ||
`greaterThan` checks if one Natural is strictly greater than another. | ||
-} | ||
|
||
let Bool/not = | ||
../Bool/not sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 | ||
? ../Bool/not | ||
|
||
let lessThanEqual = | ||
./lessThanEqual sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 | ||
? ./lessThanEqual | ||
let lessThan = | ||
./lessThan sha256:3381b66749290769badf8855d8a3f4af62e8de52d1364d838a9d1e20c94fa70c | ||
? ./lessThan | ||
|
||
let greaterThan | ||
: Natural → Natural → Bool | ||
= λ(x : Natural) → λ(y : Natural) → Bool/not (lessThanEqual x y) | ||
= λ(x : Natural) → λ(y : Natural) → lessThan y x | ||
|
||
let example0 = assert : greaterThan 5 6 ≡ False | ||
|
||
let example1 = assert : greaterThan 5 5 ≡ False | ||
|
||
let example2 = assert : greaterThan 5 4 ≡ True | ||
|
||
let property0 = λ(n : Natural) → assert : greaterThan 0 n ≡ False | ||
|
||
let property1 = λ(n : Natural) → assert : greaterThan n n ≡ False | ||
|
||
in greaterThan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
{- | ||
`greaterThanEqual` checks if one Natural is greater than or equal to another. | ||
-} | ||
let Bool/not = | ||
../Bool/not sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 | ||
? ../Bool/not | ||
|
||
let lessThan = | ||
./lessThan sha256:d8a37951fd3f88dcc3927c20b73e6c53499f5275d949eed59bb77ea748492bf0 | ||
? ./lessThan | ||
let lessThanEqual = | ||
./lessThanEqual sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 | ||
? ./lessThanEqual | ||
|
||
let greaterThanEqual | ||
: Natural → Natural → Bool | ||
= λ(x : Natural) → λ(y : Natural) → Bool/not (lessThan x y) | ||
= λ(x : Natural) → λ(y : Natural) → lessThanEqual y x | ||
|
||
let example0 = assert : greaterThanEqual 5 6 ≡ False | ||
|
||
let example1 = assert : greaterThanEqual 5 5 ≡ True | ||
|
||
let example1 = assert : greaterThanEqual 5 4 ≡ True | ||
let example2 = assert : greaterThanEqual 5 4 ≡ True | ||
|
||
let property0 = λ(n : Natural) → greaterThanEqual n 0 ≡ True | ||
|
||
let property1 = λ(n : Natural) → greaterThanEqual n n ≡ True | ||
|
||
in greaterThanEqual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
{- | ||
`lessThan` checks if one Natural is strictly less than another. | ||
|
||
Examples: | ||
|
||
``` | ||
``` | ||
-} | ||
let lessThanEqual = | ||
./lessThanEqual sha256:1a5caa2b80a42b9f58fff58e47ac0d9a9946d0b2d36c54034b8ddfe3cb0f3c99 | ||
? ./lessThanEqual | ||
let greaterThanEqual = | ||
./greaterThanEqual sha256:30ebfab0febd7aa0ccccfdf3dc36ee6d50f0117f35dd4a9b034750b7e885a1a4 | ||
? ./greaterThanEqual | ||
|
||
let Bool/not = | ||
../Bool/not sha256:723df402df24377d8a853afed08d9d69a0a6d86e2e5b2bac8960b0d4756c7dc4 | ||
? ../Bool/not | ||
|
||
let lessThan | ||
: Natural → Natural → Bool | ||
= λ(x : Natural) → λ(y : Natural) → lessThanEqual (x + 1) y | ||
= λ(x : Natural) → λ(y : Natural) → Bool/not (greaterThanEqual x y) | ||
|
||
let example0 = assert : lessThan 5 6 ≡ True | ||
|
||
let example1 = assert : lessThan 5 5 ≡ False | ||
|
||
let example2 = assert : lessThan 5 4 ≡ False | ||
|
||
let property0 = λ(n : Natural) → assert : lessThan n 0 ≡ False | ||
|
||
let property1 = λ(n : Natural) → assert : lessThan n n ≡ False | ||
|
||
in lessThan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{- | ||
`subtract m n` computes `n - m`, truncating to `0` if `m > n` | ||
-} | ||
let subtract : Natural → Natural → Natural = Natural/subtract | ||
|
||
let example0 = assert : subtract 1 2 ≡ 1 | ||
|
||
let example1 = assert : subtract 1 1 ≡ 0 | ||
|
||
let example2 = assert : subtract 2 1 ≡ 0 | ||
|
||
let property0 = λ(n : Natural) → assert : subtract 0 n ≡ n | ||
|
||
let property1 = λ(n : Natural) → assert : subtract n 0 ≡ 0 | ||
|
||
let property2 = λ(n : Natural) → assert : subtract n n ≡ 0 | ||
|
||
in subtract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this better?