Commit Graph

376 Commits

Author SHA1 Message Date
Gabriel Gonzalez
c12ff1cb67 Version 1.2.0 => 1.3.0 2017-05-17 09:09:41 -07:00
Gabriel Gonzalez
e06791c6c1 Update default.nix 2017-05-17 09:04:42 -07:00
Gabriel Gonzalez
4c69a50484 Update tutorial for latest Prelude (#59)
I've uploaded the latest Prelude to IPFS and updated the tutorial to reflect
the changes (mostly the change in the derived IPFS hash)
2017-05-17 08:31:51 -07:00
Gabriel Gonzalez
e0319ecaa5 Forbid additional characters from paths (#58)
This reduces the number of situations where users have to end a path
with a space
2017-05-16 09:17:19 -07:00
Gabriel Gonzalez
cd9c3f97e0 Update Prelude (#57)
This adds new builtins to the Prelude and also adds corresponding tests
2017-05-15 12:54:28 -07:00
Gabriel Gonzalez
d292d4bfb4 Add tests for Prelude examples (#56)
This adds tests that match the examples in the Prelude documentation and
also fixes a couple of mistakes caught along the way
2017-05-14 10:45:24 -07:00
Markus Hauck
05e7fff07f Implement Double/show and Integer/show (#54)
* Implement Integer/show

Relates to #49

* Implement Double/show

Relates to #49
2017-05-09 11:16:38 -07:00
Markus Hauck
6a6cc6e41a Implement Natural/show (#52)
* Implement Natural/show

* Rename exprFXX variables to reflect the meaning
2017-05-08 13:00:48 -07:00
Gabriel Gonzalez
40390626a4 Fix build . fold fusion tests (#51)
The previous tests for `build . fold` fusion for `Optional` values would
succeed even without fusion.  This change updates the tests to only
succeed if fusion is occurring.
2017-05-08 10:43:13 -07:00
Markus Hauck
a40cd7cb75 Implement Natural/toInteger (#50)
* Move test utils into separate module and use custom assertions

* Implement Natural/toInteger as primitive conversion

Relates to #49
2017-05-08 06:51:58 -07:00
Gabriel Gonzalez
dcff2c3bad Change tests to test source code (#48)
This change updates the test to test Dhall source code so that we're
exercising the system from end to end.  This also makes it easier to
author tests since expressions can be written as Dhall source code
instead of an abstract syntax tree.
2017-05-07 13:10:27 -07:00
Gabriel Gonzalez
6c5cacd7a2 Increase upper bound on vector (#46) 2017-05-07 08:34:39 -07:00
Gabriel Gonzalez
7db951591a Escaped field names. Fixes #31 (#43)
You can now escape an field or variable name using backticks, like this:

```haskell
    let `let` = 2
in  let `in`  = True
in  { `True` = `let`
    , `Type` = λ(`Kind` : Bool) → `Kind` && `in`
    }
```

The main purpose of this is to support arbitrary record field names when
marshalling Dhall into other file formats (such as JSON).  For example,
this Dhall configuration file:

```haskell
{ swagger = "2.0"
, parameters = {
    foo = {
      name = "foo"
    , `in` = "path"
    , type = "string"
    }
  }
  ...
}
```

... can be used to generate this JSON file:

```json
    swagger: "2.0"
    parameters:
        foo:
            name: "foo"
            in: "path"
            type: "string"
```
2017-05-07 08:34:19 -07:00
Markus Hauck
32aa2a71e1 Implement Optional/build with fusion (#44)
- Defines a new primitive `OptionalFold`
- Implements normalization:
  - inlining of Optional/build if constants are used as args
  - fusion of fold/build and build/fold
2017-05-01 12:00:15 -07:00
Gabriel Gonzalez
aeb7d16525 Add - as a valid identifier character
Part of #31, requested by @scott-fleischman

You can now use `-` in identifier names for all but the first character.
That means that this is now legal code:

```
{ resolver = "lts-8.1", extra-deps = [ "pipes-4.3.1" ] }
```

This primarily serves people who want to use "kebab-case" for their
identifier names

Normally languages do not support dash in identifier names due to
ambiguity with the subtraction operator.  For example, an identifier
like `extra-deps` could be interpreted as `extra` minus `deps`.
However, Dhall does not support subtraction and only supports unary
negation so there is no ambiguity.
2017-04-30 09:30:23 -07:00
Gabriel Gonzalez
f6b86942ec Document existing Dhall integrations in README.md 2017-04-29 16:34:00 -07:00
Gabriel Gonzalez
4b8d8438ea Update default.nix 2017-04-29 14:46:07 -07:00
Markus Hauck
ca40559cdc Add test suite (#42) 2017-04-29 14:41:53 -07:00
Markus Hauck
b99648999a Add new argument: --version (#39) (#39)
Useful to see which version of `dhall` you are currently using.
2017-04-17 12:44:33 -07:00
Gabriel Gonzalez
dc1773f1af Disallow ( and ) characters in path
The original reason for permitting `(` and `)` in paths was due to
Dhall's origins as a fork of Morte/Annah.  Morte had no built-in
operators and often imported them via the Prelude, like this:

    http://sigil.place/prelude/annah/1.0/List/(++)

Morte also adopted the Haskell convention of using parentheses for
unapplied operators, so paths required parentheses.

However, this came at a price, which was really confusing parsing errors
if the user did something like this:

    λ(x : ./type) → x

This is because the `./type)` would be parsed as a single path token and
then you'd get a downstream error due to a missing parenthesis.

Dhall, on the other hand, does not benefit much from parentheses in
paths.  Dhall already has several built-in operators and doesn't support
operator names for bound variables.  Therefore, this change eliminates
support for parentheses in paths to improve error messages and reduce
the need for explicit whitespace after paths.
2017-04-16 13:36:04 -07:00
Markus Hauck
649acf359b Increase connection timeout for imports (#37) 2017-04-16 13:00:40 -07:00
Gabriel Gonzalez
ec1bb99969 Add (//) for right-biased, non-recursive merge. Fixes #35 (#36)
The expected use of this operator is to update a record.  For example,
you can provide a record with default values, like this:

```bash
$ cat defaults
{ availabilityZone = [] : Optional Text
, placementGroup   = [] : Optional Text
}
```

... and then update or extend that record with new values using `(//)`:

```bash
$ dhall
./defaults //
{ ami = "ami-12345" -- Example of adding a new field
, availabilityZone = ["eu-west-1"] : Optional Text -- Overriding field
-- Use the default for placementGroup
}
<Ctrl-D>
{ ami : Text, availabilityZone : Optional Text, placementGroup
: Optional Text }

{ ami = "ami-12345", availabilityZone = ["eu-west-1"] : Optional Text, placementGroup = [] : Optional Text } ```
```

You can also override a field with a new type as well:

```bash
$ dhall
{ foo = 1 } // { foo = "ABC" }
<Ctrl-D>
{ foo : Text }

{ foo = "ABC" }
```
2017-04-13 17:09:09 -07:00
Gabriel Gonzalez
8e3d087ae3 Version 1.1.0 => 1.2.0 2017-04-10 19:26:12 -07:00
Gabriel Gonzalez
ef4c8b08d5 Add support for importing paths as raw Text (#34)
* Add support for importing paths as raw `Text`

Part of #23

You can now add ` as Text` to the end of any path and the raw contents at that
path will be imported as a raw `Text` literal.  For example:

```
$ dhall <<< "http://example.com as Text"
Text

"<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta
 charset=\"utf-8\" />\n    <meta http-equiv=\"Content-type\" content=\"text/html
; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width,
initial-scale=1\" />\n    <style type=\"text/css\">\n    body {\n        backgro
und-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-famil
y: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n        \n
   }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        paddi
ng: 50px;\n        background-color: #fff;\n        border-radius: 1em;\n    }\n
    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;
\n    }\n    @media (max-width: 700px) {\n        body {\n            background
-color: #fff;\n        }\n        div {\n            width: auto;\n            m
argin: 0 auto;\n            border-radius: 0;\n            padding: 1em;\n
  }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</
h1>\n    <p>This domain is established to be used for illustrative examples in d
ocuments. You may use this\n    domain in examples without prior coordination or
 asking for permission.</p>\n    <p><a href=\"http://www.iana.org/domains/exampl
e\">More information...</a></p>\n</div>\n</body>\n</html>\n"
```

* Remove unnecessary space
2017-03-31 14:55:13 -07:00
Gabriel Gonzalez
dce4b20ba4 Support ~/... syntax for importing files relative to $HOME
... as requested by @newhoggy in #23
2017-03-31 10:00:32 -07:00
Gabriel Gonzalez
e7e799f4da Fix InterpretOptions to work inside Optional/List. Fixes #33
Consider the following Haskell program:

```
{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

import Dhall hiding (auto)

import qualified Data.Text.Lazy

interpretOptions :: InterpretOptions
interpretOptions = defaultInterpretOptions
    { fieldModifier = Data.Text.Lazy.dropWhile (== '_') }

data GitRepo = GitRepo
    { _host :: Text
    , _repo :: Text
    } deriving (Generic, Interpret, Show)

data BoxConfig = BoxConfig
    { _userName        :: Text
    , _dotfilesRepo    :: Vector GitRepo
    } deriving (Generic, Interpret, Show)

main :: IO ()
main = do
    x <- Dhall.input (autoWith interpretOptions) "./config"
    print (x :: BoxConfig)
```

Before this change the above program attempts to decode a value of type:

```
{ userName : Text, dotfilesRepo : List { _host : Text, _repo : Text } }
```

... when it should be decoding a value of type:

```
{ userName : Text, dotfilesRepo : List { host : Text, repo : Text } }
```

This change ensures that `InterpretOptions` correctly propagate to elements of
`List` or `Optional` values
2017-03-27 07:00:17 -07:00
Gabriel Gonzalez
6630470651 Fix InterpretOptions to affect nested records. Fixes #33
Consider the following program which marshals a Dhall record into Haskell:

```haskell
{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

import Dhall hiding (auto)

import qualified Data.Text.Lazy

interpretOptions :: InterpretOptions
interpretOptions = defaultInterpretOptions
    { fieldModifier = Data.Text.Lazy.dropWhile (== '_') }

data GitRepo = GitRepo
    { _host :: Text
    , _repo :: Text
    } deriving (Generic, Interpret, Show)

data BoxConfig = BoxConfig
    { _userName        :: Text
    , _dotfilesRepo    :: GitRepo
    } deriving (Generic, Interpret, Show)

main :: IO ()
main = do
    x <- Dhall.input (autoWith interpretOptions) "./config"
    print (x :: BoxConfig)
```

The above program is a common pattern when mixing Dhall records with lenses
(which typically prefix the original fields with "_").

Before this change, the above program expects a record of the following type:

```
{ userName : Text, dotfilesRepo : { _host : Text, _repo : Text } }
```

Note that the sub-record ignores the `InterpretOptions` and incorrectly includes
the underscore in the expected field names.

This change fixes the derived `Interpret` instance for records to correctly
thread `InterpretOptions` to nested records.

This required a change to the `auto` method of the `Interpret` class to
accept `InterpretOptions`, otherwise there is no way to supply the
`InterpretOptions` record to sub-records.  This modified `auto` method is now
called `autoWith`.  I still include an `auto` function that uses
`defaultInterpretOptions` consistent with the old behavior.
2017-03-26 09:20:04 -07:00
Gabriel Gonzalez
8df9061fca Type annotations now bind more tightly than lambda abstraction (#30)
Now this code:

    \(x : Natural) -> x : Natural

... will be treated as equivalent to this code:

    \(x : Natural) -> (x : Natural)

This makes the behavior of type annotations consistent with Haskell and also
consistent with parsing annotated list literals, where this code:

    \(x : Natural) -> [x] : List Natural

... is equivalent to this code:

    \(x : Natural) -> ([x] : List Natural)

This also inadvertently fixes a bug in `if` parsing, which previously would
reject this expression:

    if True then True else if True then True else True

... and now the expression parses correctly
2017-03-14 16:22:02 -07:00
Gabriel Gonzalez
10d429a8f0 Fix incorrect example in README.md
Older pre-release versions of `dhall` used to
translate Haskell records to sum-types even if
they only had one alternative.  Newer versions
do not, so the example in the `README.md` is
out-of-date and needs to be fixed.
2017-03-12 12:23:24 -07:00
Gabriel Gonzalez
11ceab1dfe Support import via environment variables
You can now use `env:NAME` to syntax to import an environment variable named
`NAME`
2017-03-03 16:27:18 -08:00
Gabriel Gonzalez
2f40a462e6 Improve parsing errors. Fixes #25
This change updates parsing errors to adopt the same format as a type error,
including a helpful summary of the error (i.e. "Error: Invalid input") before
the details of the error
2017-03-03 15:25:54 -08:00
Gabriel Gonzalez
a5a84e6412 Permit trailing commas, bars. Fixes #27
You can now write expressions like these:

```
{ foo = 1, bar = 2,}
```

```
[1,2,3,]
```
2017-03-03 15:14:28 -08:00
Gabriel Gonzalez
baa08c6498 Improve localization of parsing errors
The `exprD` parser for function application was unnecessarily backtracking when
parsing the first value in the chain.  Removing the `try` for the first element
greatly improves parsing error localization.

For example, before this change the following Dhall expression:

```
{ foo = 1, bar = '2' }
```

... would give the following parse error:

```
(stdin):1:1: error: expected: "[",
    "\8704", "\955", "\\", "forall",
    "if", "let", "merge"
{ foo = 1, bar = '2' }
^
```

After this change, you now get a much better error:

```
$ dist/build/Dhall/dhall
{ foo = 1, bar = '2' }
(stdin):1:18: error: expected: "''",
    "(", "+", "-", "[", "\8704",
    "\955", "\\", "forall", "if",
    "let", "merge", built-in value,
    double, import, integer, label,
    list literal, natural,
    record literal, record type,
    string, union literal,
    union type
{ foo = 1, bar = '2' }
                 ^
```
2017-03-03 14:41:17 -08:00
Gabriel Gonzalez
505a786c6d Add support for customizing derived auto implementation. Fixes #22 (#24)
This adds a new `deriveAuto` utility that you can customize with
`InterpretOptions` in order to transform the expected field or constructor
labels that Dhall expects

The most common use of this is to support data types that prefix field names
with underscores for lens support
2017-02-23 09:35:52 -08:00
Gabriel Gonzalez
4c3eadee1f Merge pull request #21 from PierreR/master
README: update tutorial pointer to latest version
2017-02-07 13:40:38 -08:00
Pierre Radermecker
0b90bb5ba8 README: update tutorial pointer to latest version 2017-02-07 21:46:22 +01:00
Gabriel Gonzalez
3958a4b42a Version 1.0.2 => 1.1.0
Also added `CHANGELOG.md`
2017-02-05 12:34:15 -08:00
Gabriel Gonzalez
440e734e80 No list type annotation necessary in README 2017-02-05 12:13:06 -08:00
Gabriel Gonzalez
cad5c8af20 Polish source code 2017-02-05 11:23:31 -08:00
Gabriel Gonzalez
df892060aa Export InvalidType 2017-02-05 10:32:32 -08:00
Gabriel Gonzalez
782d118c97 Provide a better error message if extract fails 2017-02-05 10:31:03 -08:00
Gabriel Gonzalez
a0ad7bb6ea Update documentation 2017-02-05 09:12:45 -08:00
Gabriel Gonzalez
cc5d22f4a8 Fix documentation
We *can* auto-generate `Interpret` instances for sum types
2017-02-05 07:27:07 -08:00
Gabriel Gonzalez
6509a16070 Remove unnecessary list type annotations in documentation 2017-02-05 07:23:25 -08:00
Gabriel Gonzalez
5bb01661fd Merge pull request #19 from ttuegel/master
Generalize type of expression parser
2017-01-29 15:47:02 -08:00
Thomas Tuegel
687be80dff
Add a nix-shell expression 2017-01-29 17:27:59 -06:00
Thomas Tuegel
4d176b52e7
Generalize type of expression parser 2017-01-29 17:27:59 -06:00
Gabriel Gonzalez
fe4a9596ce Update LICENSE 2017-01-29 14:59:16 -08:00
Gabriel Gonzalez
c54353c3ee Replace microlens* dependencies with lens. Fixes #20
`trifecta` already depends on `lens`, so using `microlens` does not
actually trim down the dependency tree.  Quite the opposite: it adds two
unnecessary dependencies.
2017-01-29 14:44:09 -08:00
Gabriel Gonzalez
e16783e01d Polish source code 2017-01-29 14:37:46 -08:00