-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add support for dependent types #669
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
377b827
Add support for dependent types
Gabriella439 1e7ed19
Fix grammar for `assert`
Gabriella439 57909f8
Exercise Prelude
Gabriella439 03b2bf5
Merge branch 'master' into gabriel/dependent_types
Gabriella439 3c6a20e
Exercise Prelude ... for real this time
Gabriella439 8f5cc0a
Require that the inferred types match
Gabriella439 ca48b80
Fix precedence of `assert`
Gabriella439 bc8a16a
Update `dhall` version
Gabriella439 1b92512
Merge branch 'master' into gabriel/dependent_types
Gabriella439 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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,18 +1,14 @@ | ||
{- | ||
The `and` function returns `False` if there are any `False` elements in the | ||
`List` and returns `True` otherwise | ||
|
||
Examples: | ||
|
||
``` | ||
./and [ True, False, True ] = False | ||
|
||
./and ([] : List Bool) = True | ||
``` | ||
-} | ||
let and | ||
: List Bool → Bool | ||
= λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l && r) True | ||
|
||
let example0 = assert : and [ True, False, True ] ≡ False | ||
|
||
let example1 = assert : and ([] : List Bool) ≡ True | ||
|
||
in and |
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,17 +1,18 @@ | ||
{- | ||
`build` is the inverse of `fold` | ||
|
||
Examples: | ||
|
||
``` | ||
./build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → true) = True | ||
|
||
./build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → false) = False | ||
``` | ||
-} | ||
let build | ||
: (∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool) → Bool | ||
= λ(f : ∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool) | ||
→ f Bool True False | ||
|
||
let example0 = | ||
assert | ||
: build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → true) ≡ True | ||
|
||
let example1 = | ||
assert | ||
: build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → false) | ||
≡ False | ||
|
||
in build |
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,18 @@ | ||
{- | ||
Returns `True` if there are an even number of `False` elements in the list and | ||
returns `False` otherwise | ||
|
||
Examples: | ||
|
||
``` | ||
./even [ False, True, False ] = True | ||
|
||
./even [ False, True ] = False | ||
|
||
./even [ False ] = False | ||
|
||
./even ([] : List Bool) = True | ||
``` | ||
-} | ||
let even | ||
: List Bool → Bool | ||
= λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x == y) True | ||
|
||
let example0 = assert : even [ False, True, False ] ≡ True | ||
|
||
let example1 = assert : even [ False, True ] ≡ False | ||
|
||
let example2 = assert : even [ False ] ≡ False | ||
|
||
let example3 = assert : even ([] : List Bool) ≡ True | ||
|
||
in even |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
{- | ||
Flip the value of a `Bool` | ||
-} | ||
let not : Bool → Bool = λ(b : Bool) → b == False | ||
|
||
Examples: | ||
let example0 = assert : not True ≡ False | ||
|
||
``` | ||
./not True = False | ||
let example1 = assert : not False ≡ True | ||
|
||
./not False = True | ||
``` | ||
-} | ||
let not : Bool → Bool = λ(b : Bool) → b == False in not | ||
in not |
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,18 @@ | ||
{- | ||
Returns `True` if there are an odd number of `True` elements in the list and | ||
returns `False` otherwise | ||
|
||
Examples: | ||
|
||
``` | ||
./odd [ True, False, True ] = False | ||
|
||
./odd [ True, False ] = True | ||
|
||
./odd [ True ] = True | ||
|
||
./odd ([] : List Bool) = False | ||
``` | ||
-} | ||
let odd | ||
: List Bool → Bool | ||
= λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x != y) False | ||
|
||
let example0 = assert : odd [ True, False, True ] ≡ False | ||
|
||
let example1 = assert : odd [ True, False ] ≡ True | ||
|
||
let example2 = assert : odd [ True ] ≡ True | ||
|
||
let example3 = assert : odd ([] : List Bool) ≡ False | ||
|
||
in odd |
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,18 +1,14 @@ | ||
{- | ||
The `or` function returns `True` if there are any `True` elements in the `List` | ||
and returns `False` otherwise | ||
|
||
Examples: | ||
|
||
``` | ||
./or [ True, False, True ] = True | ||
|
||
./or ([] : List Bool) = False | ||
``` | ||
-} | ||
let or | ||
: List Bool → Bool | ||
= λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l || r) False | ||
|
||
let example0 = assert : or [ True, False, True ] ≡ True | ||
|
||
let example1 = assert : or ([] : List Bool) ≡ False | ||
|
||
in or |
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,13 +1,11 @@ | ||
{- | ||
Render a `Bool` as `Text` using the same representation as Dhall source code | ||
(i.e. beginning with a capital letter) | ||
-} | ||
let show : Bool → Text = λ(b : Bool) → if b then "True" else "False" | ||
|
||
Examples: | ||
let example0 = assert : show True ≡ "True" | ||
|
||
``` | ||
./show True = "True" | ||
let example1 = assert : show False ≡ "False" | ||
|
||
./show False = "False" | ||
``` | ||
-} | ||
let show : Bool → Text = λ(b : Bool) → if b then "True" else "False" in show | ||
in show |
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,13 +1,11 @@ | ||
{- | ||
Render a `Double` as `Text` using the same representation as Dhall source | ||
code (i.e. a decimal floating point number with a leading `-` sign if negative) | ||
-} | ||
let show : Double → Text = Double/show | ||
|
||
Examples: | ||
let example0 = assert : show -3.1 ≡ "-3.1" | ||
|
||
``` | ||
./show -3.1 = "-3.1" | ||
let example1 = assert : show 0.4 ≡ "0.4" | ||
|
||
./show 0.4 = "0.4" | ||
``` | ||
-} | ||
let show : Double → Text = Double/show in show | ||
in show |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
{- | ||
Convert an `Integer` to the corresponding `Double` | ||
-} | ||
let toDouble : Integer → Double = Integer/toDouble | ||
|
||
Examples: | ||
let example0 = assert : toDouble -3 ≡ -3.0 | ||
|
||
``` | ||
./toDouble -3 = -3.0 | ||
let example1 = assert : toDouble +2 ≡ 2.0 | ||
|
||
./toDouble +2 = 2.0 | ||
``` | ||
-} | ||
let toDouble : Integer → Double = Integer/toDouble in toDouble | ||
in toDouble |
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,17 +1,14 @@ | ||
{- | ||
Builds a key-value record such that a List of them will be converted to a | ||
homogeneous record by dhall-to-json and dhall-to-yaml. | ||
|
||
Both key and value are fixed to Text. | ||
Take a look at `Record/keyValue` for a polymorphic version. | ||
|
||
Example: | ||
|
||
``` | ||
./keyText "foo" "bar" = { mapKey = "foo", mapValue = "bar" } | ||
``` | ||
-} | ||
|
||
let keyText = | ||
λ(key : Text) → λ(value : Text) → { mapKey = key, mapValue = value } | ||
|
||
let example0 = | ||
assert : keyText "foo" "bar" ≡ { mapKey = "foo", mapValue = "bar" } | ||
|
||
in keyText |
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,20 +1,17 @@ | ||
{- | ||
Builds a key-value record such that a List of them will be converted to a | ||
homogeneous record by dhall-to-json and dhall-to-yaml. | ||
|
||
Examples: | ||
|
||
``` | ||
./keyValue Natural "foo" 2 = { mapKey = "foo", mapValue = 2 } | ||
|
||
./keyValue Text "bar" "baz" = { mapKey = "bar", mapValue = "baz" } | ||
``` | ||
-} | ||
|
||
let keyValue = | ||
λ(v : Type) | ||
→ λ(key : Text) | ||
→ λ(value : v) | ||
→ { mapKey = key, mapValue = value } | ||
|
||
let example0 = | ||
assert : keyValue Natural "foo" 2 ≡ { mapKey = "foo", mapValue = 2 } | ||
|
||
let example1 = | ||
assert : keyValue Text "bar" "baz" ≡ { mapKey = "bar", mapValue = "baz" } | ||
|
||
in keyValue |
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
Oops, something went wrong.
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.
This is fine, but would
examples = [ assert ..., assert ... ]
be cleaner?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.
Each assertion has a different type, so they can't be stored within the same list
For example, in this file the fully normalized types of the examples are: