Commit Graph

597 Commits

Author SHA1 Message Date
Gabriel Gonzalez
cffcfc257b
Document that dhall now always formats output (#366)
Fixes #364
2018-04-24 17:36:13 -07:00
Hardy Jones
8f88d7d8e8 Fix documentation for UnionLit (#360)
This was a typo from long ago.
We construct `UnionLit`s without tuples.
The documentation reflects that now.
2018-04-15 16:50:14 -07:00
Gabriel Gonzalez
ac68adc14e
Trim unnecessary extensions from Dhall.Context (#353)
The `GeneralizedNewtypeDeriving` extension was not being used at all

The `BangPatterns` extension was not necessary because the argument `n` was
already being forced before each modification
2018-04-08 20:37:47 -07:00
Gabriel Gonzalez
a0a2ac12eb
Remove unused base16-bytestring dependency (#355) 2018-04-08 20:32:56 -07:00
Gabriel Gonzalez
50a10f69d1
Add sub-commands for each interpreter phase (#352)
This adds new `dhall version`, `dhall resolve`, `dhall type`, and
`dhall normalize` subcommands.  The latter three subcommands can be used
to run just one phase of the interpreter.

If you omit the subcommand then the executable behaves the same as
before.
2018-04-07 07:10:30 -07:00
Javier Neira
8c0f09fb4d Support for ghc-7.10.3 / lts-6.27 (#340) 2018-04-06 14:39:21 -07:00
Gabriel Gonzalez
a07424a81b
Use optparse-applicative instead of optparse-generic (#351)
There are two motivations for this change:

* To slim down `dhall`'s dependency footprint
* To allow greater control over option customization
2018-04-05 07:28:35 -07:00
Gabriel Gonzalez
4f2103a769
Add support for projecting a subset of record fields (#350)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/126
2018-04-05 07:13:12 -07:00
Oliver Charles
14b083ba76 Add RecordType, record and field (#338) 2018-04-05 07:08:17 -07:00
Gabriel Gonzalez
9b5be7b223
Add whitespace before and after REPL output (#347)
This adds an additional newline before and after each output line in the
REPL so that it's easier to visually separate commands from their
results
2018-04-04 17:42:49 -07:00
Gabriel Gonzalez
d473f83ef5
Fix derived Inject instance for sum types (#348)
Related to #346

This fixes the `GenericInject` instance for a sum type with two
constructors to include the type of the alternative constructor.  For
example, before this change you would get the following incorrect
conversion:

```
$ cabal repl lib:dhall
>>> :set -XDeriveGeneric
>>> :set -XDeriveAnyClass
>>> data Amount = Debit Scientific | Credit Scientific deriving (Show, Generic, Inject, Interpret)
>>> Dhall.Core.pretty (embed inject (Debit 5.45))
"< Debit = { _1 = 5.45 } >"
```

... which is missing the `Credit` alternative.

After this change you get the correct result:

```
< Debit = { _1 = 5.45 } | Credit : { _1 : Double } >
```
2018-04-01 17:48:18 -07:00
Gabriel Gonzalez
5d99c18e29
Change :type to only print type in dhall-repl (#344) 2018-04-01 10:43:11 -07:00
Gabriel Gonzalez
b1c40fa616
Fix semantic integrity hashes (#345)
This fixes both the parsing and rendering of semantic hashes, which were
failing due to missing conversions to and from base16-encoded
bytestrings
2018-04-01 10:31:26 -07:00
Gabriel Gonzalez
21355e7858
Fix pretty-printing of source positions (#343)
This fixes the `Buildable` instance for `Src` to use
`Text.Megaparsec.sourcePosPretty` instead of `Show` to give a
nicer-looking file/line/column position for error messages
2018-03-31 08:51:10 -07:00
Gabriel Gonzalez
9cb89df6d6
Add new operator for merging record types (#342)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/117
2018-03-31 08:43:36 -07:00
Gabriel Gonzalez
4b2e428d06
Add concise types diffs to error messages (#336)
Fixes #207

This expands Dhall's error messages to include concise "type diffs"
whenever an actual type doesn't match an expected type.  For example,
here is an example diff for some small changes to a very large (6,159
lines) type:

```
dhall <<< '../dhall-to-cabal/dhall-to-cabal.dhall : ./type.dhall'

Use "dhall --explain" for detailed errors

Error: Expression doesn't match annotation

{ - license2 : …
, + license : …
,   library : …
              (   ∀(… : { arch :   ∀(… : < S390 : - Bool
                                                  + {}
                                         | …
                                         >
                                   )
                                 → …
                        , …
                        }
                  )
                → { build-tools : …
                                  { - version2 : …
                                  , + version : …
                                  , …
                                  }
                  , default-extensions : …
                                         < - NamedWildCards2 : …
                                         | - UnboxedSums : …
                                         | + DataKinds : …
                                         | + NamedWildCards : …
                                         | …
                                         >
                  , …
                  }
              )
, …
}

../dhall-to-cabal/dhall-to-cabal.dhall : ./type.dhall
```

These type diffs are always emitted (i.e. present even if the user does
not supply the `--explain` flag).
2018-03-28 08:43:24 -07:00
Oliver Charles
922e20e6ab Replace trifecta with megaparsec (#268)
The long-term motivation for this change is so that we can eventually use a
separate `attoparsec`-based lexing step to greatly increase parsing speed since
the `trifecta`/`parsers` API doesn't allow tokens other than `Char`.

The secondary motivation for this is that `megaparsec` is a smaller dependency
that is more actively maintained.
2018-03-27 09:09:20 -07:00
Gabriel Gonzalez
0ffe854d6d
Restrict records to forbid storing both types and terms (#335)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/120
2018-03-25 18:16:11 -07:00
Gabriel Gonzalez
7d7b8590b5
Version 1.11.1 → 1.12.0 (#334) 2018-03-24 09:51:45 -07:00
Gabriel Gonzalez
ed2041ee77
Make dhall -Wcompat clean (#331)
This fixes Dhall to exactly match the guidance given in
https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid for
compatibility with GHC 8.4
2018-03-19 19:24:01 -07:00
Joe Kachmar
c87e5d9980 Switches from text-format to formatting (#330) 2018-03-18 22:05:30 -07:00
Gabriel Gonzalez
4a085aa3d6
Version 1.11.0 → 1.11.1 (#323) 2018-03-12 11:09:54 -07:00
Gabriel Gonzalez
02380b6095
Increase upper bound on exceptions (#325) 2018-03-12 11:02:02 -07:00
Gabriel Gonzalez
62490b8407
Increase weight of highlighted syntax (#324)
This bolds the green highlighted syntax so that it's easier to visually
navigate on white backgrounds
2018-03-12 08:25:33 -07:00
Gabriel Gonzalez
610b877af5
Build against ansi-terminal-0.8 (#322) 2018-03-11 07:44:41 -07:00
Gabriel Gonzalez
99c6241111
Fix α-normalization bug (#319)
This fixes α-normalization to correctly relabel a `let`-bound variable
2018-03-10 09:30:01 -08:00
Kosyrev Serge
bd83658409 Parser, Chunks: add Semigroup instances for SMP/GHC 8.4 compat (#321) 2018-03-10 09:26:25 -08:00
Gabriel Gonzalez
ab436c78ca
Version 1.10.0 → 1.11.0 (#318) 2018-03-08 20:24:13 -08:00
Gabriel Gonzalez
2dae2c7e92
Update Prelude references (#317) 2018-03-06 20:29:56 -08:00
Gabriel Gonzalez
d287f02089
Implement new simplifications for boolean logic (#316)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/109
2018-03-06 20:04:17 -08:00
Paul Cadman
5a9126b2f6 Fix a typo in the docs for Union constructors (#315) 2018-03-04 12:09:13 -08:00
Gabriel Gonzalez
00c79f5d65
Implement standard simplifications (#312)
There are many symbolic simplifications that the semantics require such
as `+0 + x ⇥ x` and `if b then True else False ⇥ b`.  This change
implements those simplifications.
2018-03-02 22:19:36 -08:00
Gabriel Gonzalez
404c97d96c
Add --plain flag to disable syntax highlighting (#310)
... as requested by @PierreR
2018-03-01 13:45:51 -08:00
Pi3r
5d2012927a Replace cryptohash with cryptonite (#313)
Fixes #305
2018-03-01 07:32:20 -08:00
Gabriel Gonzalez
da41f8cc06
Add :save command to dhall-repl (#309)
Now you can do:

```
⊢ :save x = 2
⊢ ./x
2
```
2018-02-28 14:42:34 -08:00
Gabriel Gonzalez
d8647eb490
Split example tests out into test files (#311)
Fixes #20

This migrates `tests/Examples.hs` to use a language-independent test
file format so that other implementations can reuse these tests
2018-02-28 14:12:59 -08:00
Gabriel Gonzalez
3561266756
Fix test import (#308)
One of the tests had a remote import, which this changes to a relative
import so that the test suite won't fail if the network is down.
2018-02-28 14:06:05 -08:00
Gabriel Gonzalez
b5d0b1613d
Fix equivalence check to match standard semantics (#307)
Fixes #299

The standard mandates that two terms that are α-equivalent and
β-equivalent should be equal for type-checking purposes, but the
implementation was not matching the standard.  Specifically, a
type with an anonymous function would never compare as equal to
itself.

The newly added regression test shows an example of where the previous
implementation was misbehaving, where `λ(x : Type) → List x` would
not compare as equal to itself before.  After this change it correctly
matches itself since it is (obviously) the exact same type.

This also adds a new `alphaNormalize` function which was implemented
along the way, which converts an expression to α-normal form using
De Bruijn indices.
2018-02-28 13:58:45 -08:00
Vanessa McHale
2b9b3a735e loosen upper bound on exceptions library (#306) 2018-02-27 17:20:34 -08:00
Gabriel Gonzalez
6b56aa5a0f
Fix semantics of {List,Optional,Natural}/build (#300)
This fixes all of the build built-ins  to match the standard semantics

The easiest way to illustrate the problem is the following example from
the test suite:

```haskell
  λ(id : ∀(a : Type) → a → a)
→ Natural/build
  (   λ(natural : Type)
    → λ(succ : natural → natural)
    → λ(zero : natural)
    → id natural (succ zero)
  )
```

According to the standard semantics that should normalize to:

```haskell
λ(id : ∀(a : Type) → a → a) → id Natural +1
```

... but before this change it was not reducing at all.  After this
change it reduces correctly.

However, there is a further issue, which is that correctly implementing
the semantics leads to poor time complexity for `List/build` since it is
specified in terms of repeatedly prepending a single element, which
leads to quadratic time complexity since lists are implemented in terms
of `Vector` under the hood.

You might think that you could use the efficient approach for
expressions like this:

```haskell
List/build
Bool
( λ(list : Type)
→ λ(cons : Bool → list → list)
→ λ(nil : list)
→ cons True (cons False nil)
)
```

... and then fall back on the slower approach for more interesting cases
such as this:

```haskell
  λ(id : ∀(a : Type) → a → a)
→ List/build
  Bool
  ( λ(list : Type)
  → λ(cons : Bool → list → list)
  → λ(nil : list)
  → id list (cons True (cons False nil))
  )
```

... but that does not work either!  The reason why is that very often
you don't use `List/build` directly and instead use it indirectly via
helper functions such as `Prelude/List/concat`:

```haskell
let concat : ∀(a : Type) → List (List a) → List a
    =   λ(a : Type)
    →   λ(xss : List (List a))
    →   List/build
        a
        (   λ(list : Type)
        →   λ(cons : a → list → list)
        →   λ(nil : list)
        →   List/fold
            (List a)
            xss
            list
            (   λ(xs : List a)
            →   λ(ys : list)
            →   List/fold
                a
                xs
                list
                cons
                ys
            )
            nil
        )

in  concat
```

... so what happens is that if you try to normalize something like:

```haskell
concat Text [["Example"]]
```

... the `concat` function will be normalized first, which will cause the
`List/build` to be normalized when its argument is still abstract, which will
trigger the slow path for the semantics.

Consequently, this change also modifies Dhall lists to be backed by
`Data.Sequence.Seq` instead of `Data.Vector.Vector`, so that
`List/build` can always use the correct implementation of semantics
in linear time while still implementing other operations on lists
reasonably efficiently.

This in turn triggers another change to the `OptionalLit` constructor
to use `Maybe` to store the payload instead of `Vector`.  The only
reason that `OptionalLit` originally used `Vector` was so that
`List/head` and `List/last` could be implemented as just a slice into
the `ListLit` vector, but now that it's not a vector any longer it's
simpler to just use a more accurate `Maybe` type to represent the
payload.
2018-02-26 10:50:27 -08:00
Gabriel Gonzalez
4b3f28374c
Always format output of the dhall executable (#303)
Fixes #284
2018-02-25 14:31:38 -08:00
Gabriel Gonzalez
1bd7884c05
Normalize values inserted into context (#302)
This simplifies the context and in each case the value being inserted is
safe to insert because either:

* The value was type-checked, indicating that it is safe to normalize, or:
* The value is the output of type inference, which is also safe to normalize
2018-02-25 14:26:44 -08:00
Gabriel Gonzalez
eb33770fc2
Sort fields when type-checking (#301)
This change ensures that the fields of a record or union are sorted
before comparing for equality.

I thought the old code was sorting the fields, but later learned that
neither `Data.HashMap` nor `Data.HashMap.Strict.InsOrd` guarantee any
ordering on the fields in their conversions and they have no `Ord`
constraints in their API.  Similarly, the `toSortedList` function had
no `Ord` constraint before this change.

However, what's suprising is that I could not devise a failing test case
despite the suspicious lack of sorting.  So it may be that there was
some sorting going on under the hood that I wasn't aware of but I'm
still sorting the results just to be safe.
2018-02-25 14:17:57 -08:00
Gabriel Gonzalez
60a734edcf
Create package for Prelude (#298)
This creates a single expression that users can import for convenience to obtain
a record with all Prelude utilities
2018-02-25 11:59:21 -08:00
Gabriel Gonzalez
78b91b8534
Version 1.9.1 → 1.10.0 (#288) 2018-02-23 19:54:58 -08:00
Gabriel Gonzalez
c676ae7f10
Increase upper bound on optparse-generic (#296) 2018-02-23 19:44:55 -08:00
Gabriel Gonzalez
c2329c52f4
Don't pretty-print header for dhall executable (#289)
The main reason for this change is stylistic (`dhall` doesn't need to
preserve the header because it's not filling the same purpose as
`dhall-format`)

The other reason for this is that `renderIO` was displaying the header
for both the type and the normalized expression.  Rather than complicate
the code to fix this I felt it was easier to just remove the
header-printing logic.
2018-02-21 09:08:53 -08:00
David Luposchainsky
2adc29aa56 Housekeeping (#293)
* Add explicit Prettyprinter dep to stack.yaml until LTS supports it

* Remove redundant dependencies

Courtesy of Weeder,
https://hackage.haskell.org/package/weeder
2018-02-21 08:47:15 -08:00
Gabriel Gonzalez
be7a5771ea
Use the latest prettyprinter library (#287)
This fixes the root cause of e24b3d90fa so
that we no longer need the workaround of using `Pretty.Text.renderIO`
2018-02-19 11:05:11 -08:00
Gabriel Gonzalez
8e1acafac4
Enforce -Werror in CI (#286)
This adds the `-Werror` flag to CI so that warnings don't sneak into the
build (and also fixes the current set of warnings)
2018-02-19 10:31:21 -08:00