Commit Graph

289 Commits

Author SHA1 Message Date
Gabriel Gonzalez
47383de623 Update Dhall.Tutorial module (#1439)
* Update `Dhall.Tutorial` module

This overhauls the `Dhall.Tutorial` module to reflect recent changes to
the language (and also to link to external documentation when possible).

* Fix doctests

* Rephrase import syntax caveat

... as suggested by @sjakobi

* Explain `<<<`

... as suggested by @sjakobi@

* Rephrase things

... as suggested by @sjakobi

* `s/The annotated/This/`

... as caught by @sjakobi

* Add commas to description of link to built-ins reference

... as caught by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Remove paragraph describing role of Prelude

* Update dhall/src/Dhall/Tutorial.hs

... as suggested by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-20 00:38:07 +00:00
Simon Jakobi
a944d12591 Add --file option for dhall hash (#1445)
To use the existing utilities in Dhall.Main more easily, I have moved
the implementation to Dhall.Main.
2019-10-19 22:38:44 +00:00
Simon Jakobi
bec6ce610f Move syntax things from Dhall.Core to a new module Dhall.Syntax (#1440)
This partially addresses #1127.
2019-10-19 20:13:22 +00:00
Steven Leiva
c284c19c11 Add --no-cache to dhall type. (#1441) 2019-10-19 13:47:27 +00:00
Simon Jakobi
301477de59 Rename Interpret to FromDhall, Inject to ToDhall (#1437)
* Rename Interpret to FromDhall

The "Interpret" name remains in `InterpretOptions`, which are
actually used for marshalling in both directions.

* s/injectThenInterpretIsIdentity/embedThenExtractIsIdentity

* s/Inject/ToDhall

* s/shouldInjectInto*/shouldEmbedAs*

* Keep Interpret and Inject as constraint synonyms for compatibility

… as suggested by @Gabriel439.
2019-10-19 03:24:49 +00:00
Steven Leiva
270adddf37 Add --no-cache flag to dhall resolve. (#1436) 2019-10-19 02:40:27 +00:00
Simon Jakobi
b75962a405 Use a more conventional spelling for "etags", mostly just use "tags" (#1432)
The previous "ETags" spelling was likely to cause confusion with HTTP ETags:
https://en.wikipedia.org/wiki/HTTP_ETag
2019-10-19 01:59:29 +00:00
Steven Leiva
9d739b553a Do not warn about cache on --no-cache. (#1434) 2019-10-18 20:33:53 +00:00
Gabriel Gonzalez
58fcc6fe90 Fix formatting in error message (#1429) 2019-10-17 08:51:56 +00:00
Gabriel Gonzalez
03ca91baca
Fix CI to properly reject incomplete haddocks (#1418)
My first attempt to do this in #1416 did not correctly reject incomplete
haddocks, which this change fixes
2019-10-16 19:49:44 -07:00
tenniscp25
a343b19a63 Marshalling HashMap (#1394) (#1426) 2019-10-16 15:53:33 +00:00
Frederik Ramcke
3f6a5ad8df Restore idempotency when formatting comments (#1415)
* Move prefix out of renderSrc

This reduces the complexity of renderSrc slightly without affecting
anything else much.

* Make formatting of comments idempotent

Fixes #1413. Previously the formatter would insert an additional line
break before some comments whilst preserving existing line breaks. In
order to restore idempotent behaviour, we need to strip a leading
newline character from the comment string in those cases, if present.

* Test idempotency when formatting comments

Test case taken from @AJChapman's bug report (#1413).

* Change argument order of renderSrc

Reads a bit more idiomatic, as suggested by @sjakobi.
2019-10-15 15:01:10 +00:00
Jie
1cd856a449 [#1392] Injecting Data.Map (#1412)
* [#1392] Injecting Data.Map

* injecting via Generic

* Explicit instance

* Cleanup code

* Minor code cleanup

* Property testing for Inject/Interpret

* Refactor test

* Adding TypeApplications to .cabal

* No more TypeApplications

* Simplified tests using extract

* Added test for Text amnf fixed Natural import

* Update dhall/dhall.cabal

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Update dhall/dhall.cabal

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-15 11:27:29 +00:00
Gabriel Gonzalez
17fb0e3c46
100% haddock coverage (#1416)
This updates the `dhall` package to have 100% haddock coverage and
also updates CI to enforce this going forward.

This also includes a change to deprecate the `X` type synonym, which
I noticed along the way
2019-10-13 22:22:39 -07:00
Gabriel Gonzalez
4b8b8cd730
Add new record completion operator (#1375)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/767
2019-10-11 08:26:51 -07:00
Jie
34f706ed93 [#1395] Marshalling Set and HashSet (#1405)
* [#1395] Marshalling Set and HashSet

* Update dhall/src/Dhall.hs

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Update dhall/src/Dhall.hs

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Added distinctList

* setFromDistinctList updates

* Doctests abour ordering

* both set and hashset can ignore or fail with duplicates

* Comments on instances

* Moved length computation deeper

* Little wibble

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-10 16:31:44 +00:00
Dima
5b8ae442c8 Add tags subcommand (#1398)
Fixes #370.
2019-10-10 16:16:20 +02:00
Gabriel Gonzalez
a24ddfc3b9 Add support for leading separators (#1355)
* Add support for leading separators

... as standardized in https://github.com/dhall-lang/dhall-lang/pull/755

Note that this does not yet change the formatter to use them

* Update `dhall-lang` submodule

* Fix `dhall.cabal` to mention new Prelude files

* Remove duplicate lines
2019-10-10 05:01:34 +00:00
Michael Gilliland
1dba96c2c8 Resolves #1408: Add more detail in --explain when toMap has the w… (#1411)
* Resolves #1408: Add more detail in `--explain` when `toMap` has the wrong type.

Specifically, add common reason of using `{}` for record value.

For example,
``` shell
echo 'toMap {}' | ~/.local/bin/dhall
```

Outputs

> Error: ❰toMap❱ expects a record value
>
> Explanation: You can apply ❰toMap❱ to any homogenous record, like this:
>
>
>     ┌─────────────────────────────────────────────────────────────────────┐
>     │ let record = { one = 1, two = 2 }
> │
>     │ in  toMap record : List { mapKey : Text, mapValue : Natural}
> │
>     └─────────────────────────────────────────────────────────────────────┘
>
>
> ... but the argument to ❰toMap❱ must be a record and not some other
> type.
>
> Some common reasons why you might get this error:
>
> ● You accidentally provide an empty record type instead of an empty
> record when
>   using ❰toMap❱:
>
>
>     ┌──────────┐
>     │ toMap {} │
>     └──────────┘
>             ⇧
>             This should be ❰{=}❱ instead
>
> ────────────────────────────────────────────────────────────────────────────────
>
> 1│ toMap {}
>
> (stdin):1:1

* Add type annotation to `toMap` suggestion.
2019-10-09 23:54:42 +00:00
Jie
3e5cb34922 [#1381] Word* types to Natural, not Integer (#1387)
* #1381 Word* to Natural

* Added instance for Word

* Got rid of linting issues

* Added docsets

* Added comments

* Revert Crypto to master version

* Spread the doctests

* Improve Docstring
2019-10-07 17:54:42 +00:00
Andika Demas Riyandi
bf40ec52a1 add --output options to dhall (#1399) 2019-10-07 09:51:30 +00:00
Simon Jakobi
5e7794c652
Update dhall-lang submodule (#1403)
This includes some simplifications/optimizations for the `ToTerm DhallDouble` instance.

Most notably we let `cborg` take care of the correct encoding of NaNs:
See `Codec.CBOR.Write.doubleMP`:
  977c0c0820/cborg/src/Codec/CBOR/Write.hs (L571-L573)
2019-10-07 10:39:59 +02:00
Andika Demas Riyandi
9de7ac51a8 dhall: make lazyText use strictText (#1401) 2019-10-06 14:00:22 +00:00
Jie
cc3e50eaf1 [#1378] instance Interpret () (#1388)
* [#1378] instance Interpret ()

* Remove instance from tests
2019-10-06 03:46:25 +00:00
Curtis
c8ddedcc8c [#1389] Change Interpret [a] to use list (#1397) 2019-10-06 02:02:08 +00:00
Simon Jakobi
d172e4b677 Add 'instance Interpret (Map k v)' (#1391)
… and helper 'Type's 'map' and 'pairFromMapEntry'
2019-10-05 16:37:58 +00:00
Simon Jakobi
613a44d512 Add Interpret and Inject instances for Void (#1382) 2019-10-04 06:06:38 +00:00
Simon Jakobi
94ff61b152 Fix formatting of multi-argument function applications (#1380)
merge-expressions with additional arguments are also formatted with
consistent indentation for all arguments. E.g.

    merge
      { x = Natural/even }
      < x >.x
      1111111111111111111111111111111111111111111111111111111111

Fixes a small regression introduced in 7634ee7.
2019-10-04 04:47:51 +00:00
Simon Jakobi
7538552a7f Always break annotated let-bindings (#1372)
Fixes #1370.
2019-10-04 03:42:15 +00:00
Simon Jakobi
7634ee740b Fix indentation for multiline Some-, toMap- and merge-expressions (#1377)
The loss of indentation for toMap and merge was due to
75e6cc5ca7. I have included Some for
consistency.

Fixes #1376.

Also improve format test failure messages
2019-10-03 22:59:42 +00:00
Simon Jakobi
6bc182a08a Move parser-pretty-printer note to D.Pretty.Internal (#1374)
I've toned it down a bit since the correspondence doesn't seem
to be as close anymore as it once was.

Fixes #1364.
2019-10-03 02:49:27 +00:00
Simon Jakobi
5a2ee1ca57 Improve type-inference of annotated list literals (#1366)
* Remove a redundant check of the type annotation.

* Replace dead code for processing the list elements
  with an error.

* Document the ListLit invariant.

Closes https://github.com/dhall-lang/dhall-haskell/issues/1359.
2019-10-02 05:17:03 +00:00
Simon Jakobi
a44fb420a5 Delete Dhall.Parser.Expression.renderChunks (#1363)
This is dead code.
2019-10-02 03:47:45 +00:00
Simon Jakobi
a4b4cfb1b3 infer: Remove redundant checks for field selections and record projections (#1368)
… as pointed out by @MonoidMusician in #741.
2019-10-02 01:41:18 +00:00
Gabriel Gonzalez
75e6cc5ca7 Fix pretty-printing precedence of toMap (#1360)
* Fix pretty-printing precedence of `toMap`

Fixes https://github.com/dhall-lang/dhall-haskell/issues/1358

* Also correctly format `merge` expressions without a type annotation

... as suggested by @sjakobi

* Add test for formatting "function-like" expressions

This verifies that the code correctly handles `toMap` expressions with
type annotations as @sjakobi was asking about
2019-10-01 04:01:22 +00:00
Gabriel Gonzalez
e707db04ec Remove unnecessary type-checking step (#1362)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1361
2019-10-01 02:56:57 +00:00
Simon Jakobi
d6d3943fe5 Update type-inference of annotated expressions (#1337)
… as standardized in https://github.com/dhall-lang/dhall-lang/pull/745.

This also adds proper error handling for the free variable case
discussed in https://github.com/dhall-lang/dhall-lang/issues/749:

Sample output for the MergeHandlerFreeVar test case:

    Error: Disallowed handler type

    Explanation: You can ❰merge❱ the alternatives of a union using a record with one
    handler per alternative, like this:

        ┌─────────────────────────────────────────────────────────────────┐
        │ let union    = < Left : Natural | Right : Bool >.Left 2         │
        │ let handlers = { Left = Natural/even, Right = λ(x : Bool) → x } │
        │ in  merge handlers union : Bool                                 │
        └─────────────────────────────────────────────────────────────────┘

    ... but the output type of a handler may not depend on the input value.

    For example, the following expression is not valid:

          Invalid: The output type is ❰Optional A❱, which references the input
          value ❰A❱.
                      ⇩
        ┌──────────────────────────────────────────┐
        │ merge { x = None } (< x : Type >.x Bool) │
        └──────────────────────────────────────────┘

    Your handler for the following alternative:

    ↳ x

    ... has type:

    ↳ ∀(A : Type) → Optional A

    ... where the output type:

    ↳ Optional A

    ... references the handler's input value:

    ↳ A

    ────────────────────────────────────────────────────────────────────────────────

    1│ merge { x = None } (<x: Type>.x Bool)

    dhall/dhall-lang/tests/type-inference/failure/unit/MergeHandlerFreeVar.dhall:1:1
2019-09-29 12:52:41 +00:00
Gabriel Gonzalez
5595801b4e Add dhall lint support for fixing malformed assertions (#1353)
* Add @dhall lint@ support for fixing malformed assertions

* s/==/≡/

... as caught by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-09-28 21:44:12 +00:00
Simon Jakobi
7c91dd5f48 Fix Expr's Eq instance via a newtype wrapper for Doubles (#1347)
See the haddocks in Dhall.Core for details.

Fixes #1341.
2019-09-28 14:56:37 +00:00
Simon Jakobi
acd5144ef7 dhall repl: Don't normalize inferred types (#1338)
Context: #1300
2019-09-26 17:33:42 +00:00
Simon Jakobi
72bf46b600 Add a Show instance for Val (#1344)
Since Val contains functions, its Show instance cannot be
derived in the usual way without exposing a non-standard Show
instance for (Val a -> Val a). Instead, we rely on the user to
provide a fitting instance, e.g. by importing Text.Show.Functions.
2019-09-26 15:58:51 +00:00
Simon Jakobi
f825dd18d9 Add link to GHC ticket for rounding issue in Integer/toDouble (#1348) 2019-09-26 15:13:43 +00:00
Gabriel Gonzalez
1682c4c5f2 Fix inferred type for record projection (#1342)
This ensures that record projection correctly sorts the fields in the
inferred type

This fixes the regression test in
https://github.com/dhall-lang/dhall-lang/pull/750
2019-09-25 02:34:51 +00:00
Javier Neira
08747af8d3 Warn about missing cache directory (#1320)
* Warning action about missing cache dir

* Add warning to executable

* Correct duplicate cacheName in getCacheFile

* Warn if dhall-haskell cache dir is not usable

* Improve warn message

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Correct plural

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Improve syntax

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Use runMaybeT to make 2 step warnings

* Add FlexibleContexts to make happy lts-6

* Catch IOException's when handling cache dir

This make the haskell impl follow the standard.

* Correct unwanted identantion

* Push warnings to get* wrapper functions

* Remove unnecessary lang extension

* Inline warnings in get* functions

* Being consistent with break lines

* Apply suggestions from code review

About phrasing, formatting, syntax, etc

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* doesPathExist is not in directory-1.2.2.0

* Make message fit in 80 cols
2019-09-24 08:59:58 +00:00
Gabriel Gonzalez
95809b467d
Use Dhall.Eval for type-checking (#1335)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1306

The following comment describe how this works in depth:

https://github.com/dhall-lang/dhall-haskell/issues/1129#issuecomment-532928798

The short explanation is that we can substantially speed up type-checking
by not substituting `let` expressions and instead adding the bound variable
to the context.  This is the same as the type-checking "fast path" that
we had before adding dependent types, except this time it works even in the
presence of dependent types.

The main difference is that we add the `let`-bound type *and* value to the
context and use `Dhall.Eval.conv` to perform equivalence checking instead of
`Dhall.Core.judgmentallyEqual`.
2019-09-22 10:37:26 -07:00
Gabriel Gonzalez
183cc9291a Add --censor flag support for censoring type errors (#1329)
* Add `--censor` flag support for censoring type errors

Fixes https://github.com/dhall-lang/dhall-haskell/issues/1294

* Reuse `censorText`

... as caught by @sjakobi

* Remove `typeWith` refactor

... as caught by @sjakobi

This is a vestige of a refactor that I reverted incompletely

* Reuse `Dhall.Core.censorText` in `Dhall.Parser` module

... as suggested by @sjakobi
2019-09-22 04:44:51 +00:00
Simon Jakobi
b556a65644 Handle --version consistently (#1334)
* dhall --version

* dhall-to-bash --version

* dhall-to-nix --version

* dhall-lsp-server --version
2019-09-22 03:55:26 +00:00
Vanessa McHale
fe748e2884
Dhall version (#1332)
* Add Dhall.Version module

* Add Paths_dhall to Autogen-Modules
2019-09-20 15:53:13 +00:00
Patrick Mylund Nielsen
fa84b0dc19
Different with-http CPP check; fix remote imports in GHCJS (#1330)
Completes the changes in #1311
2019-09-20 10:44:15 -04:00
Gabriel Gonzalez
54241f88c7 Disable 1-field simplification by default (#1321)
* Disable 1-field simplification by default

This builds on top of #1315 to minimize disruption by disabling the
breaking change by default and instead requiring the user to opt in
by setting a new `collapseSingletonRecords` option to `True`.

The additional tests added to verify this also caught a bug in the
`Interpret` instance for functions, which this change also fixes.

* Change to three-valued option

... based on feedback from @sjakobi

This change the option to a three-valued option:

* `Bare`    - 1-field constructor does not include a nested record
* `Wrapped` - 1-field constructor always includes a nested record
* `Smart`   - Named fields that don't begin with `_` include a nested record

The default is `Wrapped` (for backwards compatibility), but users will
probably want to eventually switch to `Smart`

* Don't depend on `fieldModifier` for determining if a field is anonymous

... as suggested by @sjakobi
2019-09-19 07:07:23 +00:00