Skip to content

Conversation

@ocharles
Copy link
Member

Fixes #906.

I copied the approach used in dhall-json.

k' <- Dhall.Map.keys kts
return (k', Nothing)
let e2 = Fix (NSym k)
return (Fix (NAbs (ParamSet e0 False Nothing) e2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this compiles < Foo >.Foo to { Foo }: Foo, but I believe the result should instead be: x: { Foo }: Foo x

Copy link
Member Author

@ocharles ocharles Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Foo>.Foo compiling to {Foo}: Foo seems correct to me, and is the current behavior. What is that x about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. Never mind, my thoughts were confused

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I remember what led to my confusion. The issue here is that you need to check if the alternative is empty when compiling the union to Nix.

For example:

dhallToNix "< Foo >.Foo" = { Foo }: Foo

dhallToNix "< Foo : {} >.Foo {=}" = { Foo }: Foo {}

dhallToNix "< Foo : {} >.Foo" = x: { Foo }: Foo x

Carefully note the difference between the 1st and 3rd examples. If the type of the alternative is present then you need to turn it into an anonymous function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so it's a case of < .. >.x being partially applied when the alternative does take data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I believe my latest commit resolves this.

@ocharles
Copy link
Member Author

Here's the latest behaviour:

[nix-shell:~/work/dhall-haskell/dhall-nix]$ ./dist/build/dhall-to-nix/dhall-to-nix <<< '<Foo : {} | Bar>.Foo'
x:
  { Bar, Foo }:
    Foo x

[nix-shell:~/work/dhall-haskell/dhall-nix]$ ./dist/build/dhall-to-nix/dhall-to-nix <<< '<Foo : {} | Bar>.Foo {=}'
{ Bar, Foo }:
  Foo {}

[nix-shell:~/work/dhall-haskell/dhall-nix]$ ./dist/build/dhall-to-nix/dhall-to-nix <<< '<Foo : {} | Bar>.Bar'
{ Bar, Foo }:
  Bar

@Gabriella439
Copy link
Collaborator

@ocharles: I think you need to import join: https://hydra.dhall-lang.org/build/10741/nixlog/2/tail

@ocharles
Copy link
Member Author

Ah no, I just need to push another commit

@ocharles ocharles merged commit d3d7baf into dhall-lang:master Apr 27, 2019
@ocharles ocharles deleted the dhall-nix-union-field branch April 27, 2019 10:17
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.

dhall-to-nix generate incorrect Nix for sum types

2 participants