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

Fix derived Inject instance for sum types #348

Merged
merged 1 commit into from Apr 2, 2018

Conversation

Gabriella439
Copy link
Collaborator

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 } >

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 } >
```
@srid
Copy link
Contributor

srid commented Apr 1, 2018

I've verified that this fixes it!

Getting < Debit = { _1 = 4.88 } | Credit : { _1 : Double } >

@Gabriella439
Copy link
Collaborator Author

Awesome! Thanks for verifying that :)

@Gabriella439 Gabriella439 merged commit d473f83 into master Apr 2, 2018
@Gabriella439 Gabriella439 deleted the gabriel/fix_sum_inject branch April 2, 2018 00:48
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

Successfully merging this pull request may close these issues.

None yet

2 participants