Commit Graph

14 Commits

Author SHA1 Message Date
Simon Jakobi
e931451a2b Format more text literals as multi-line strings (#1508)
This causes text literals to be formatted as multi-line strings
whenever they contain at least one newline and at least one non-newline
character. "Spacers" like `"\n\n"` continue be formatted as single-line
strings. If the heuristic turns out to be too eager to choose a
multi-line layout, we can refine it later.

This partially addresses #1496.

Also

* update some variable names

* use 80-column "smart" layout consistently
2019-11-04 03:31:49 +00:00
Simon Jakobi
d5b7c3860e
Rename Type to Decoder, InputType to Encoder (#1485)
* s/InputType/Encoder

* Rename input* functions on the ToDhall side to encode*

* Haddocks: Use "encoder" instead of "injector"

* s/Type/Decoder

* Haddocks: Stop using the word "parser" for Decoders

* Rename encode{Record,Union} to {record,union}Encoder
2019-10-30 14:24:15 +01: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
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
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
Frederik Ramcke
36379cec2e Fix import alternatives to recover from type errors (#1152)
Previously, `BAD="0 0" dhall <<< "env:BAD ? 0"` resulted in the
following error:
```
↳ env:BAD

Error: Not a function

1│ 0 0

BAD:1:1
```

According to the standard the above expression was supposed to evaluate
successfully to `0`. See #1146 for further discussion.
2019-07-25 18:05:55 -07:00
Frederik Ramcke
4faf25bbbe Load imports recursively (#1128)
* Load imports recursively

This is the big change that enables us to implement 'semi-semantic'
caching.

* Use `throwM` instead of `liftIO . throwIO`

* Fix build with __GHCJS__

* Fix exceptions in Dhall.Import

* Fix dhall-lsp-server

* Revert exception behaviour on typecheck errors

This is one for a separate pull request!

* Make sure loadImportFresh returns alpha-normal expression

As caught by @Gabriel439, `loadImportFresh` violated the invariant that
`ImportSemantics` should be alpha-beta-normal. This fix also means that
we don't have to alpha-normalise again in `loadImportWithSemanticCache`.

* Remove old comment

* Fix regression test for issue 216

Turns out the test was testing the wrong thing, because it was
pretty-printing an import. This worked previously because when importing
uncached expressions we would not alpha-normalise them.

* Restore `dhall freeze` bevhaviour

Newly frozen imports should also be present in the cache.
2019-07-23 16:11:33 +00:00
Simon Jakobi
e40e847730 Always typecheck the type annotation on 'toMap' (#1132)
Previously, ill-typed expressions like this one got into normalization:

    toMap {=} : <>.x

Also:

* Tweak Expr's Arbitrary instance:
  - Boring nullary constructors don't need to be so frequent.
  - Large NaturalLits can cause normalization to OOM, which we don't
    want when running the testsuite.

* Add property test to check that all well-typed expressions can be
  normalized.
2019-07-19 23:14:01 +00:00
Gabriel Gonzalez
af0e77ce00
Consistently format multi-line strings (#1056)
Fixes #973

The formatter was behaving inconsistently for multi-line strings
depending on whether or not they were at the top level or nested as
a subexpression.  For example, the same multi-line string would be
rendered in multi-line form if it was at the top level and rendered
compactly if nested within another expression.

The root cause was that the pretty-printing logic was missing a top-level
`Pretty.group` call (which is the function responsible for enabling
compact representations if they fit), which this change fixes.
2019-07-02 13:54:54 -07:00
Javier Neira
95dc3daae8 Eta support for dhall-json (#1013)
After #989 and #993 the use of the `yaml` package is isolated in the lib modules `Dhall.Yaml` and `Dhall.YamlToDhall` so it is easier to add support for compilers that cant use the `yaml`package like eta or ghcjs.

With this one we would add support for [eta](https://eta-lang.org/), a fork of ghc that compiles to jvm bytecode.

Main changes:

* Add conditional to cabal file and cpp conditions to the main modules for yaml to use a specific module for eta, `Dhall.Yaml.Eta` that replaces calls to the `yaml`package to ffi calls to the java lib [jackson](https://github.com/FasterXML/jackson), one of the most popular ones in the java world.
* Add the java files that contains the ffi calls
* Mark  `buildable: False` the subpackages that cant be built by eta for now

One effect of use the cabal file for cabal and etlas (the build tool for eta) is stack and cabal builds show those warnings:

```
Warning: Cabal file warning in D:\ws\eta\dhall\dhall-haskell\dhall-json\dhall-js
on.cabal@ 69:9:
         Unknown field: "maven-depends"

Warning: Cabal file warning in D:\ws\eta\dhall\dhall-haskell\dhall-json\dhall-js
on.cabal@ 74:9:
         Unknown field: "java-sources"
```

I've not found a way to avoid them other than use another file for etlas build (`etlas.dhall`). It would suppose duplicate most of the logic, though.
2019-06-18 17:45:01 -07:00
Gabriel Gonzalez
a2ab6a59ec
Add support for empty alternatives (#863)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/438

This also adds `dhall-json` support for empty alternatives

In particular, this translates empty alternatives to strings encoding the alternative name

```haskell
-- ./example.dhall

let Role = < Wizard | Fighter | Rogue >

in  [ Role.Wizard, Role.Fighter ]
```

```
$ dhall-to-json <<< './example.dhall'
["Wizard","Fighter"]
```
2019-03-27 15:29:10 -07:00
Gabriel Gonzalez
36f0e55a5f
Remove the constructors keyword (#829)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/385
2019-02-27 21:44:36 -08:00
Gabriel Gonzalez
6ab5df4d49
Implement standardized support for multi-line literals (#726)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/307

Note that this a breaking change because:

* Newlines are now mandatory after the opening `''` of a multi-line
  literal
* The spaces before the trailing `''` count towards the leading
  indentation computation
2018-12-08 08:49:08 -08:00
Gabriel Gonzalez
83c4a32e99
Refactor test suite (#733)
This moves all of the test suite modules underneath a `Dhall.Test`
module hierarchy instead of clobbering the top-level namespace.
2018-12-03 09:17:53 -08:00