dhall-lang / dhall-json

This repository has moved to https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json
BSD 3-Clause "New" or "Revised" License
65 stars 6 forks source link

list of unions not converted to maps #71

Open alexhumphreys opened 5 years ago

alexhumphreys commented 5 years ago

I'm writing some GoCD pipeline configs in dhall and ran into the following issue. Given this dhall file:

let MaterialSource =
  { mapKey : Text
  , mapValue :
    { git : Text
    , branch : Text
    }
  }
in let MaterialPipeline =
  { mapKey : Text
  , mapValue :
    { pipeline : Text
    , stage : Text
    }
  }
in let Material = < Source : MaterialSource | Pipeline : MaterialPipeline >
in let unionMaterial = constructors Material
in let Materials = List Material
in let materials : Materials =
  [ unionMaterial.Source
    { mapKey = "someRepo"
    , mapValue =
      { git = "www.example.com/user/repo.git"
      , branch = "master"
      }
    }
  , unionMaterial.Pipeline
    { mapKey = "somePipeline"
    , mapValue =
      { pipeline = "someOtherPipeline"
      , stage = "build"
      }
    }
  ]
in materials

I get this output:

- mapKey: someRepo
  mapValue:
    branch: master
    git: www.example.com/user/repo.git
- mapKey: somePipeline
  mapValue:
    stage: build
    pipeline: someOtherPipeline

whereas I would have expected:

someRepo:
    branch: master
    git: www.example.com/user/repo.git
somePipeline:
    stage: build
    pipeline: someOtherPipeline

I'm new to dhall so it's likely i'm doing something wrong, any help would be appreciated.

f-f commented 5 years ago

Hi @alexhumphreys! The development of dhall-json has moved to dhall-haskell, so maybe we could move that issue there.

This said, I believe you are right and this is currently not supported. In fact, it looks like the homogeneous records conversion is applied specifically to lists, while unions go through unconverted. I think the conversion logic could be pulled out and applied in other places, but need to think how far we can take this 🤔

alexhumphreys commented 5 years ago

Hey @f-f, thanks for the heads up about the move, i'll copy paste this issue over there and close it here. And yeah adding support for this would be cool, though I can imagine there might be some work involved alright.

Gabriella439 commented 5 years ago

Yeah, I will need to go through the merged repositories and mark them clearly so that people know that they have been migrated