Commit Graph

63 Commits

Author SHA1 Message Date
Gabriel Gonzalez
0091b09183
Add support for Scientific (#256)
Fixes https://github.com/dhall-lang/dhall-lang/issues/86

This change has two benefits:

* Users of the Haskell API can now marshal Dhall values of type `Double` into
  Haskell values of type `Scientific`
* The `dhall` executable no longer loses precision when dealing with
  values that have a large exponent (see the newly added test)
2018-02-08 07:24:12 -08:00
Oliver Charles
0e7d620fa8 Add Interpret String (#247) 2018-02-01 21:20:18 -08:00
Gabriel Gonzalez
067ff6d939
dhall-format now preserves the order of fields (#246)
Related to #244

This updates Dhall's syntax tree to use an insert-ordered hashmap to store
record fields and union alternatives.  This in turn implies that they will be
formatted in the same order that they were originally parsed.

This is a breaking change to the API due to changing the type of map used in the
syntax tree.
2018-02-01 21:16:24 -08:00
Oliver Charles
430fc08f45 Add unit, string, pair and list types (#227) 2018-01-22 16:38:42 -08:00
Gabriel Gonzalez
4e94f631ea
Preserve string interpolation when using dhall-format (#220)
Fixes #216

This changes the internal representation of `TextLit` to be able to
store an interpolated string literal.  Preserving string interpolation in
the syntax tree means that `dhall-format` can also preserve
interpolation.

This also simplifies a lot of the string-interpolation-related code,
which is now simpler and more strongly typed.
2018-01-21 16:32:28 -08:00
Oliver Charles
2ae05f9dad Add 'inputWith' (#222)
'inputWith' is like 'input', but allows for a custom typing context and
normalizer.

Fixes #213.
2018-01-21 16:31:29 -08:00
Gabriel Gonzalez
593434ffbd
Add genericAuto (#195)
Fixes #156
2017-12-28 10:17:45 -08:00
Armando Ramirez
28db97ca91 Simpe custom typechecking for Embedded terms (#186) 2017-12-05 11:01:44 -08:00
bosu
0e8a4c9b25 Add Inject instance for () (#147) 2017-09-29 12:49:34 -07:00
bosu
9e0ab9a755 Inject instances for Data.Set, Data.Sequence (#113) 2017-08-28 08:58:46 -07:00
bosu
a03de76a41 Add Inject instances for Word types (#112) 2017-08-27 16:06:57 -07:00
bosu
5b1cbb08af Implement Inject instance for unnamed tuples. (#107)
This removes the need for `R2`
2017-08-26 08:02:52 -07:00
bosu
b58100759d Interpret instance for unnamed data fields (#103)
Maps unnamed data fields to the positional record keys. For example:

```haskell
data Foo = Foo Bool Integer Natural deriving (Generic, Interpret)
```

... is mapped to this Dhall data type:

```haskell
Record { _1 : Bool, _2 : Integer, _3 : Natural }
```
2017-08-22 13:30:28 -07:00
Gabriel Gonzalez
63a8bf0976 Small tweaks to documentation of R2 (#101)
This slightly modifies the documentation of `R2` to further clarify its
relationship to 2-tuples
2017-08-21 19:10:08 -07:00
Gabriel Gonzalez
27264a0ba4 Add Interpret/Inject instances for [] 2017-08-21 11:36:59 -07:00
bosu
fa51d5e40e Add Inject, Interpret instances for tuples. (#100)
Uses R2 intermediate type to represent tuples in Dhall.
2017-08-21 09:08:51 -07:00
bosu
2a186dcabb Add Inject instance for Int (#99) 2017-08-20 10:24:24 -07:00
bosu
333fc1d000 Export InputType (#91) 2017-07-27 11:44:37 -07:00
Gabriel Gonzalez
8b3ebbc832 Remove use of Template Haskell. Fixes #89
This replaces all uses of `NeatInterpolation` with either multi-line
strings or `unlines`.  This allows Dhall to be compiled without using
Template Haskell, which in turn enables cross-compilation
2017-07-25 19:51:40 -07:00
Gabriel Gonzalez
fae3232480 Add support for marshaling simple Dhall functions to Haskell functions (#88) 2017-07-22 04:53:24 -07:00
bosu
0221dd4432 Exports Type internals. (#86)
Adds trivial comments on extend, extract functions.

Fixes https://github.com/Gabriel439/Haskell-Dhall-Library/issues/26.
2017-07-11 14:04:44 -07:00
Ville Tirronen
4707a8ff62 Raw input (#85)
Added a function that allows doing `input` from a closed
Dhall `Expr` instead of text. This is hugely useful when
working with Dhall in AST level (for example, using custom
types / normalization). For example, suppose that you have
built a custom primitive that requires a record as an argument.
With `rawInput` you can just extract the record into a Haskell
data type and process it without need to work with maps and other
bits of AST.

For context of this commit, see #79 (and also #26).
2017-07-05 09:05:47 -07:00
Chris Martin
7a0c03df57 add Type and Interpret instance for strict Text (#82) 2017-07-01 22:24:39 -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
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
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
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
17290171fe Make Dhall -Wall-clean 2017-01-29 14:10:28 -08:00
Gabriel Gonzalez
961278d71a Change derived Interpret for data types with 1 constructor
They no longer need to be wrapped inside a union with 1 alternative and are
decoded directly from a record
2016-12-05 07:33:09 -08:00
Gabriel Gonzalez
20831bc24d Remove unnecessary first argument to load 2016-12-04 15:29:07 -08:00
Gabriel Gonzalez
94d7e99408 Update documentation 2016-12-04 15:19:01 -08:00
Gabriel Gonzalez
6e927f62f1 Tidy up pretty-printing logic 2016-12-04 15:10:27 -08:00
Gabriel Gonzalez
88776fd570 Update documentation 2016-11-24 22:13:36 -08:00
Gabriel Gonzalez
e34ce03ea4 Update documentation 2016-11-24 19:15:29 -08:00
Gabriel Gonzalez
96fe0ededb Update documentation 2016-11-24 14:59:02 -08:00
Gabriel Gonzalez
44fe3f7d6b Update documentation 2016-11-20 21:19:35 -08:00
Gabriel Gonzalez
38c0cd4866 Add detailed 2016-11-20 16:25:55 -08:00
Gabriel Gonzalez
7fe24bc8c4 Rename Maybe to Optional
The primary reason for this change is to make it easier to describe these values
both in documentation and in informal communication between developers.

Before, you'd have to say things like:

* A value of type `Maybe` (incorrect)
* A `Maybe` value (sounds weird)
* A value of type `Maybe a` for some `a` (correct, but very verbose)

Now you can say an `Optional` value and the meaning is precise and clear

A secondary reason for this change is to keep the terminology close to the
intended use of the language for configuration files.  Describing fields as
`Optional` instead of `Maybe` makes a lot of sense for configurations.

The disadvantage is that some uses of `Optional` don't make sense.  For example,
consider the type of `List/head`:

    List/head : ∀(a : Type) → List a → Optional a

It seems weird to say that the result of `List/head` is `Optional`.  However,
many languages (such as Java/Scala/F#/Swift) already use this name or `Option` and
they get along just fine.
2016-11-12 08:31:13 -08:00
Gabriel Gonzalez
1ac704ad76 Add source annotation for values read into Haskell via input 2016-11-05 08:36:16 -07:00
Gabriel Gonzalez
e3850beed6 Use (stdin) and (input) in Trifecta error messages
... instead of `(interactive)`
2016-11-03 09:40:29 -07:00
Gabriel Gonzalez
9b7aa9dad3 Remove old parser implementation 2016-10-30 19:31:47 -07:00
Gabriel Gonzalez
13eddef662 Initial switch to new trifecta-based parser
Still several bugs to work out
2016-10-30 18:33:14 -07:00
Gabriel Gonzalez
2909f8871b Add Note constructor 2016-10-29 21:48:18 -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
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
79ed8f300e Add support for decoding sum types into Haskell 2016-10-15 17:35:51 -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