Commit Graph

1391 Commits

Author SHA1 Message Date
Gabriel Gonzalez
bc7735d5c2 Update documentation 2016-10-19 16:54:47 -07:00
Gabriel Gonzalez
43bcda1a47 Update documentation 2016-10-19 09:15:57 -07:00
Gabriel Gonzalez
323cbdf289 Move the X type to the Dhall.TypeCheck module
... since it's not used in the `Dhall.Core` module at all
2016-10-18 09:18:01 -07:00
Gabriel Gonzalez
3d9661817f Improve efficiency of Context implementation
The old list-based implementation was tuned for Morte and more efficient for
type-checking typical Morte expressions (such as Church-encoded bytes), that had
multiple occurrences of the same key.  I'm still not sure why it was more
efficient, though, but it may have been due to better use of laziness.

However, these sorts of expressions are rare in idiomatic Dhall code, so we use
the more direct approach using a `Map` for faster lookup of the outer keys and
a `Seq` for faster indexing into the elements associated with a given key.
2016-10-18 08:56:30 -07:00
Gabriel Gonzalez
e4abd4fdfc Remove unnecessary Context export from Dhall.Core 2016-10-17 19:49:06 -07:00
Gabriel Gonzalez
51a86a1ec8 Move type-checking logic to separate Dhall.TypeCheck module
The error messages alone warranted separating this out into a separate module
2016-10-17 18:34:51 -07:00
Gabriel Gonzalez
2da9f35f19 Fix error message 2016-10-16 18:01:10 -07:00
Gabriel Gonzalez
d6ecb421e4 Remove support for function arguments to let bindings
In other words, instead of writing:

    let f (x : Natural) = x + 1
    in  ...

... you must now write:

    let f = λ(x : Natural) → x + 1
    in  ...

The reason for this is two-fold:

* The implementation is much simpler, which matters for porting Dhall to other
  languages
* This is more consistent with handlers for the newly added `apply` notation,
  where the handlers have to be expressed as anonymous functions
2016-10-16 13:26:55 -07:00
Gabriel Gonzalez
ecdc6c832e Add pattern matching in the form of the apply command
Example usage:

        let handlers = { Left = Natural/even, Right = \(x : Bool) -> x }
    in  let union    = < Left = +2 | Right : Bool >
    in  apply handlers union : Bool
2016-10-16 10:37:43 -07:00
Gabriel Gonzalez
8b94bf4189 Remove absurd 2016-10-16 08:34:43 -07:00
Gabriel Gonzalez
dc3b0fcf66 Update documentation 2016-10-16 08:24:30 -07:00
Gabriel Gonzalez
ac49ae5fcc Use : in syntax for union types 2016-10-16 08:21:47 -07:00
Gabriel Gonzalez
48144b5b92 Revert "Permit field access for unions with one element"
This reverts commit 98ef584a67.
2016-10-16 08:19:08 -07:00
Gabriel Gonzalez
79ed8f300e Add support for decoding sum types into Haskell 2016-10-15 17:35:51 -07:00
Gabriel Gonzalez
e3b54792d1 Remove List/concat
This can be implemented in terms of `List/build` and `List/fold`, and those
permit build/fold fusion, unlike `List/concat`
2016-10-14 21:13:38 -07:00
Gabriel Gonzalez
6f35500d8e Add build/fold fusion 2016-10-14 20:10:17 -07:00
Gabriel Gonzalez
4187b92a7b Fix shift error for if statements 2016-10-14 20:06:50 -07:00
Gabriel Gonzalez
7b2a418269 Go back to | as the separator for union types and literals
This is easier on the eyes when writing out sums of products, like:

    < Just = { foo = 1, bar = True } | Nothing : {} >
2016-10-11 20:21:25 -07:00
Gabriel Gonzalez
a371529a6e Add union literals
Also, replace the `|` with `,` for union types and literals
2016-10-11 20:12:40 -07:00
Gabriel Gonzalez
98ef584a67 Permit field access for unions with one element
Note that I haven't even implemented union literals, so this can't even be used,
yet!

This lets you access the field of a union if it has exactly one alternative.

The basic idea is that a subsequent change will provide an operator for merging
pattern matches with the following pseudo-type:

    a : Type, b : Type, r : Type |- (\/) : (a → r) → (b → r) → (a \/ b → r)

For example:

        (\/)
    :   (< foo : Bool > → Integer)
    →   (< bar : Text > → Integer)
    →   (< foo : Bool | bar : Text > → Integer)

You can then combine `(\/)` in conjunction with field access to implement
pattern matching:

    let example : < foo : Bool | bar : Natural > → Bool =
            (λ(x : < foo : Bool    >) → x.foo               )
        \/  (λ(x : < bar : Natural >) → Natural/even (x.bar))
    in  example
2016-10-11 17:26:11 -07:00
Gabriel Gonzalez
ebe96b3cac Update documentation 2016-10-11 09:36:29 -07:00
Gabriel Gonzalez
9505637891 Use (++) to concatenate Text instead of (<>)
This ensures that `<>` unambiguously refers to the empty sum type
2016-10-11 09:32:02 -07:00
Gabriel Gonzalez
1602f891f1 Remove (++)
There are two main reasons that I'm removing `(++)`:

* I would like to use `(++)` instead of `(<>)` for combining `Text` so that
  `<>` can be used for the empty sum type
* `(++)` leads to quadratic time complexity when used repeatedly.  `List/concat`
  is the preferred API for combining lists
2016-10-11 09:26:04 -07:00
Gabriel Gonzalez
7ea9c2a972 Remove Text/concat
The original motivation for adding `Text/concat` was to work around the
quadratic time complexity of using `(<>)` repeatedly, but this is no longer an
issue now that Dhall uses `Builder` internally to represent `Text`
2016-10-11 09:21:40 -07:00
Gabriel Gonzalez
91a933ba9a Use Builder internally for representing Text
This is more efficient since the only thing we ever do is concatenate text,
which `Builder` is optimized for.
2016-10-11 09:18:52 -07:00
Gabriel Gonzalez
a49bad9a58 Add absurd 2016-10-11 09:02:12 -07:00
Gabriel Gonzalez
718fdeb171 Add union types
Just the types for now.  No union literals or pattern matching, yet
2016-10-02 14:32:35 -07:00
Gabriel Gonzalez
89ea6b038c Polish code 2016-10-02 13:53:59 -07:00
Gabriel Gonzalez
727ffb86e1 Change {}/{:} to {=}/{}, respectively 2016-10-02 08:34:46 -07:00
Gabriel Gonzalez
03cc365e7b Revert "Add syntax for pattern types and literals (i.e. sum types)"
This reverts commit 954e8619b6.
2016-09-27 09:39:21 -07:00
Gabriel Gonzalez
954e8619b6 Add syntax for pattern types and literals (i.e. sum types) 2016-09-21 20:39:40 -07:00
Gabriel Gonzalez
f34b07be49 Remove List/splitAt and List/splitAtEnd 2016-09-20 08:46:40 -07:00
Gabriel Gonzalez
158429b988 Improved error messages for lexer 2016-09-18 22:18:36 -07:00
Gabriel Gonzalez
c199d04956 Update documentation 2016-09-18 21:36:31 -07:00
Gabriel Gonzalez
afa3844699 Add back Buildable instance for Const 2016-09-18 21:31:27 -07:00
Gabriel Gonzalez
d36eabb0af Update documentation 2016-09-18 21:28:21 -07:00
Gabriel Gonzalez
80b9b25d24 Update documentation 2016-09-18 21:13:03 -07:00
Gabriel Gonzalez
3e9d230498 Add Natural/even and Natural/odd 2016-09-18 21:07:49 -07:00
Gabriel Gonzalez
e597a97e78 Add Text/concat 2016-09-18 18:45:34 -07:00
Gabriel Gonzalez
6e74794a76 Add List/concat 2016-09-18 18:31:23 -07:00
Gabriel Gonzalez
1260b92fdc Rename ListConcat constructor to ListAppend 2016-09-18 18:18:08 -07:00
Gabriel Gonzalez
eb4e482380 Rename fields generated by List/indexed 2016-09-18 18:09:11 -07:00
Gabriel Gonzalez
324a29be12 Rename List/first to List/head 2016-09-18 17:54:58 -07:00
Gabriel Gonzalez
11a06ab540 Replace drop/dropEnd with splitAt/splitAtEnd 2016-09-18 17:50:45 -07:00
Gabriel Gonzalez
1332f6cfb0 Fix pretty-printing of (==) and (/=) to match parser 2016-09-18 17:34:56 -07:00
Gabriel Gonzalez
16c72f5a76 Add (==) and (/=) 2016-09-18 16:28:03 -07:00
Gabriel Gonzalez
076678f1de Add support for decoding Maybes 2016-09-18 15:38:36 -07:00
Gabriel Gonzalez
d39cf8876e Re-export Text 2016-09-18 15:24:54 -07:00
Gabriel Gonzalez
429dbd266b Update documentation 2016-09-18 15:24:42 -07:00
Gabriel Gonzalez
acd77292ef Reintroduce indexed variables
The simpler approach still permitted variable capture.  For example, this would
break:

    \x -> (\y -> (\x -> y)) x

That should reduce to:

    \x -> \x -> x@1  -- ... not even expressible under the simpler system

... but it actually reduced to:

    \x -> \x -> x

This also required disabling multi-`let` since in the process of fixing this I
realized that this expression is ambiguous:

    \(x : Type) ->
    let x : Type = Bool
    let f (y : x) = y
    in  f   -- ^ Which `x` does this refer to

... because it's supposed to be semantically equivalent to:

    \(x : Type) ->
    (   \(x : Type)
    ->  \(f : forall (y : x) -> x)
    ->  f              -- ^ This refers to the inner `x : Type`
    )
    Bool
    (\(y : x) -> y)
        -- ^ ... but this refers to the outer `x : Type`

Now the code only permits a single `let` binding in each `let ... in` expression
2016-09-18 14:22:45 -07:00