Skip to content

Commit

Permalink
Fix InterpretOptions to work inside Optional/List. Fixes #33
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gabriella439 committed Mar 27, 2017
1 parent 6630470 commit e7e799f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ instance Interpret Text where
autoWith _ = text

instance Interpret a => Interpret (Maybe a) where
autoWith _ = maybe auto
autoWith opts = maybe (autoWith opts)

instance Interpret a => Interpret (Vector a) where
autoWith _ = vector auto
autoWith opts = vector (autoWith opts)

{-| Use the default options for interpreting a configuration file
Expand Down

0 comments on commit e7e799f

Please sign in to comment.