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

1.22: union construction seems not to be normalised #915

Closed
quasicomputational opened this issue Apr 28, 2019 · 4 comments · Fixed by #918
Closed

1.22: union construction seems not to be normalised #915

quasicomputational opened this issue Apr 28, 2019 · 4 comments · Fixed by #918

Comments

@quasicomputational
Copy link
Collaborator

quasicomputational commented Apr 28, 2019

Running this program against current HEAD (44a2750)

{-# LANGUAGE OverloadedStrings #-}

import qualified Dhall

license :: Dhall.Type ()
license = Dhall.union $ mconcat
  [ Dhall.constructor "AllRightsReserved" Dhall.unit
  ]

main :: IO ()
main = do
  let
    settings = Dhall.defaultInputSettings
  Dhall.input
    license
    "< AllRightsReserved : {} >.AllRightsReserved {=}"

results in this output

foobar: Error: Invalid Dhall.Type                                                  
                                                                                
Every Type must provide an extract function that succeeds if an expression      
matches the expected type.  You provided a Type that disobeys this contract     
                                                                                
The Type provided has the expected dhall type:                                  
                                                                                
↳ < AllRightsReserved : {} >
                                                                                
and it couldn't extract a value from the well-typed expression:                 
                                                                                
↳ < AllRightsReserved : {} >.AllRightsReserved {=}

By copying in the definition of union, unionType, etc, and sticking in some judicious debugging prints, the source of the failure's narrowed to this statement:

UnionLit fld e1 rest <- Just e0

The expression isn't a UnionLit, but rather an App of the field of the union and then the empty record. It looks very much like something's not being normalised properly - or perhaps this is expected in 1.22, and union needs to learn how to massage the expression into the form that it needs?

@quasicomputational
Copy link
Collaborator Author

Also, I should note that this worked in 1.21 (or, well, something with very much the same shape did), so either it's a regression or needs a heads-up in the changelog.

@AndrasKovacs
Copy link
Collaborator

You're right, it appears that Dhall.union only accepts old-style union literals. I am not sure what the fix should be, of the following two alternatives: a) parsing both union styles in Dhall.union b) parsing only new-style unions, but normalizing old-style to the new style.

@Gabriella439
Copy link
Collaborator

Yeah, the bug here is that Dhall.union doesn't accept new-style union literals. In version 7.0.0 of the standard union literals have two valid normal forms (which will go away once we remove the old-style union literals). See:

https://github.com/dhall-lang/dhall-lang/blob/master/standard/%CE%B2-normalization.md#unions

In other words, the new-style union literal of the form < AllRightsReserved : {} >.AllRightsReserved {=} is already in normal form

@Gabriella439
Copy link
Collaborator

Fix is up here: #918

quasicomputational added a commit to quasicomputational/dhall-haskell that referenced this issue May 1, 2019
I discovered it wasn't working right in dhall-lang#926. The underlying bug is
very similar to dhall-lang#915, and in fact this builds on the fix for that in dhall-lang#918.

It looks like the single-constructor case is a different underlying
bug that I don't understand just yet, so let's tackle that separately.
quasicomputational added a commit to quasicomputational/dhall-haskell that referenced this issue May 1, 2019
The underlying bug is very similar to dhall-lang#915, and in fact this builds on
the fix for that in dhall-lang#918.

Closes dhall-lang#926.
quasicomputational added a commit to quasicomputational/dhall-haskell that referenced this issue May 2, 2019
The underlying bug is very similar to dhall-lang#915, and in fact this builds on
the fix for that in dhall-lang#918.

Closes dhall-lang#926.
Gabriella439 pushed a commit that referenced this issue May 2, 2019
The underlying bug is very similar to #915, and in fact this builds on
the fix for that in #918.

Closes #926.
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 a pull request may close this issue.

3 participants