Skip to content
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 9 commits into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 4 additions & 8 deletions Prelude/Bool/and
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
17 changes: 9 additions & 8 deletions Prelude/Bool/build
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 =
Copy link
Collaborator

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?

Copy link
Contributor Author

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:

example0 : True  True

example1 : False  False

assert
: build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → true) ≡ True

let example1 =
assert
: build (λ(bool : Type) → λ(true : bool) → λ(false : bool) → false)
≡ False

in build
20 changes: 8 additions & 12 deletions Prelude/Bool/even
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
12 changes: 4 additions & 8 deletions Prelude/Bool/fold
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
{-
`fold` is essentially the same as `if`/`then`/else` except as a function

Examples:

```
./fold True Natural 0 1 = 0

./fold False Natural 0 1 = 1
```
-}
let fold
: ∀(b : Bool) → ∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool
Expand All @@ -17,4 +9,8 @@ let fold
→ λ(false : bool)
→ if b then true else false

let example0 = assert : fold True Natural 0 1 ≡ 0

let example1 = assert : fold False Natural 0 1 ≡ 1

in fold
12 changes: 5 additions & 7 deletions Prelude/Bool/not
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
20 changes: 8 additions & 12 deletions Prelude/Bool/odd
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
12 changes: 4 additions & 8 deletions Prelude/Bool/or
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
12 changes: 5 additions & 7 deletions Prelude/Bool/show
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
12 changes: 5 additions & 7 deletions Prelude/Double/show
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
12 changes: 5 additions & 7 deletions Prelude/Function/compose
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{-
Compose two functions into one.

Examples:

```
./compose Natural Natural Bool (λ(n : Natural) → n + n) ../Natural/even 3
= True
```
-}
let compose
: ∀(a : Type) → ∀(b : Type) → ∀(c : Type) → (a → b) → (b → c) → a → c
Expand All @@ -18,4 +11,9 @@ let compose
→ λ(x : A)
→ g (f x)

let example0 =
assert
: compose Natural Natural Bool (λ(n : Natural) → n + n) Natural/even 3
≡ True

in compose
12 changes: 5 additions & 7 deletions Prelude/Integer/show
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
Render an `Integer` as `Text` using the same representation as Dhall source
code (i.e. a decimal number with a leading `-` sign if negative and a leading
`+` sign if non-negative)
-}
let show : Integer → Text = Integer/show

Examples:
let example0 = assert : show -3 ≡ "-3"

```
./show -3 = "-3"
let example1 = assert : show +0 ≡ "+0"

./show +0 = "+0"
```
-}
let show : Integer → Text = Integer/show in show
in show
12 changes: 5 additions & 7 deletions Prelude/Integer/toDouble
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
11 changes: 4 additions & 7 deletions Prelude/JSON/keyText
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
15 changes: 6 additions & 9 deletions Prelude/JSON/keyValue
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
12 changes: 4 additions & 8 deletions Prelude/List/all
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{-
Returns `True` if the supplied function returns `True` for all elements in the
`List`

Examples:

```
./all Natural Natural/even [ 2, 3, 5 ] = False

./all Natural Natural/even ([] : List Natural) = True
```
-}
let all
: ∀(a : Type) → (a → Bool) → List a → Bool
Expand All @@ -17,4 +9,8 @@ let all
→ λ(xs : List a)
→ List/fold a xs Bool (λ(x : a) → λ(r : Bool) → f x && r) True

let example0 = assert : all Natural Natural/even [ 2, 3, 5 ] ≡ False

let example1 = assert : all Natural Natural/even ([] : List Natural) ≡ True

in all
12 changes: 4 additions & 8 deletions Prelude/List/any
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{-
Returns `True` if the supplied function returns `True` for any element in the
`List`

Examples:

```
./any Natural Natural/even [ 2, 3, 5 ] = True

./any Natural Natural/even ([] : List Natural) = False
```
-}
let any
: ∀(a : Type) → (a → Bool) → List a → Bool
Expand All @@ -17,4 +9,8 @@ let any
→ λ(xs : List a)
→ List/fold a xs Bool (λ(x : a) → λ(r : Bool) → f x || r) False

let example0 = assert : any Natural Natural/even [ 2, 3, 5 ] ≡ True

let example1 = assert : any Natural Natural/even ([] : List Natural) ≡ False

in any
Loading