Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultInterpretOptions is not inherited from parent record #33

Closed
PierreR opened this issue Mar 26, 2017 · 5 comments
Closed

defaultInterpretOptions is not inherited from parent record #33

PierreR opened this issue Mar 26, 2017 · 5 comments

Comments

@PierreR
Copy link
Contributor

PierreR commented Mar 26, 2017

Given this code:

auto :: (GenericInterpret (Rep a), Generic a) => Type a
auto = deriveAuto
  ( defaultInterpretOptions { fieldModifier = Data.Text.Lazy.dropWhile (== '_') })

data GitRepo
  = GitRepo
  { _host :: LText
  , _repo :: LText
  } deriving (Generic, Show)

data BoxConfig
  = BoxConfig
  { _userName        :: LText
  , _dotfilesRepo    :: GitRepo
  } deriving (Generic, Show)

makeLenses ''BoxConfig
makeLenses ''GitRepo

instance Interpret GitRepo
instance Interpret BoxConfig

boxConfig :: IO BoxConfig
boxConfig = Dhall.input auto "/vagrant/config/box"

It will force me to have this config file:

{ userName       = "John Doe"
, dotfilesRepo   = { _host = "github", _repo = "jdoe/dotfiles.git"}
}

but I wish to have

{ userName       = "John Doe"
, dotfilesRepo   = { host = "github", repo = "jdoe/dotfiles.git"}
}
@PierreR
Copy link
Contributor Author

PierreR commented Mar 26, 2017

@Gabriel439 Thanks for the quick fix ! Works like a charm.

@PierreR
Copy link
Contributor Author

PierreR commented Mar 27, 2017

@Gabriel439 I am now using a list and it doesn't bubble down ...

{ userName       = "John Doe"
, additionalRepos = [ { checkout = "vcsh clone git://github.com/PierreR/dotfiles.git",
                        push = "vcsh dotfiles push git@mygithub.com:PierreR/dotfiles.git" }
                    ]                            ]
}
data MrRepo
  = MrRepo
  { _checkout :: LText
  , _push     :: LText
  } deriving (Generic, Show)

data BoxConfig
  = BoxConfig
  { _userName        :: LText
  , _additionalRepos :: Vector MrRepo
  } deriving (Generic, Show)
Error: Expression doesn't match annotation
/vagrant/config/box : { additionalRepos : List { _checkout : Text, _push : Text }, userName : Text }

Gabriella439 added a commit that referenced this issue Mar 27, 2017
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
@Gabriella439
Copy link
Collaborator

Latter issue fixed by e7e799f

@PierreR
Copy link
Contributor Author

PierreR commented Mar 27, 2017

Thanks for the quick fix !

@Gabriella439
Copy link
Collaborator

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants