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

Maping fields order is not preserved #64

Open
majkrzak opened this issue Jun 24, 2022 · 3 comments
Open

Maping fields order is not preserved #64

majkrzak opened this issue Jun 24, 2022 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@majkrzak
Copy link

Encoding the following mapping

encode [mapping ["a" .= (1 :: Int), "d" .= (2 :: Int), "c" .= (3 :: Int), "b" .= (4 :: Int)]]

results in:

a: 1
b: 4
c: 3
d: 2
@sjakobi
Copy link
Collaborator

sjakobi commented Jun 24, 2022

Is this a feature request?

@majkrzak
Copy link
Author

Depend how to treat it. According to https://yaml.org/spec/1.2.2/#3221-mapping-key-order mapping key order is not important, but from the point of readability is.

@sjakobi
Copy link
Collaborator

sjakobi commented Jun 25, 2022

I agree that preserving the field order is desirable. I'd be happy to accept a PR that implements this.

I think we need to be a bit careful not to introduce a performance regression with this though:

-- | YAML mapping
type Mapping loc = Map (Node loc) (Node loc)

A simple list of pairs might be too slow during lookups:

 type Mapping loc = [(Node loc, Node loc)]

So a type similar to Dhall.Map might be a better choice.

@sjakobi sjakobi added enhancement New feature or request help wanted Extra attention is needed labels Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants