Commit Graph

51 Commits

Author SHA1 Message Date
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
Gabriel Gonzalez
076678f1de Add support for decoding Maybes 2016-09-18 15:38:36 -07:00
Gabriel Gonzalez
d39cf8876e Re-export Text 2016-09-18 15:24:54 -07:00
Gabriel Gonzalez
0da0968147 Polish documentation 2016-09-16 20:23:12 -07:00
Gabriel Gonzalez
d0a4134e25 Reintroduce Unicode support 2016-09-16 20:16:46 -07:00
Gabriel Gonzalez
c5b781e03e Change list literal syntax
Move the type annotation outside the list

This is to prepare for an equivalent syntax for `Maybe` literals
2016-09-15 09:34:55 -07:00
Gabriel Gonzalez
6580a4cbf1 Change [ a ] to List a 2016-09-15 09:03:12 -07:00
Gabriel Gonzalez
a4c2b5bca7 Update documentation 2016-09-12 21:27:47 -07:00
Gabriel Gonzalez
5cc537824b Update documentation 2016-09-12 21:20:55 -07:00
Gabriel Gonzalez
d3998b09a2 Switch to happy for parsing and simplify the alex lexer 2016-09-11 20:38:37 -07:00
Gabriel Gonzalez
f6990dd1af Update tutorial 2016-09-11 10:55:34 -07:00
Gabriel Gonzalez
d03a900583 Update documentation 2016-09-09 19:02:13 -07:00
Gabriel Gonzalez
b313facaa2 Update documentation 2016-09-09 09:51:31 -07:00