Visitar URL original
More simplifications for field selection by sjakobi · Pull Request #1174 · dhall-lang/dhall-haskell · GitHub
Skip to content

More simplifications for field selection - #1174

Merged
mergify[bot] merged 2 commits into
masterfrom
sjakobi/field-selection-simplifications
Jul 31, 2019
Merged

mergify[bot] merged 2 commits into
masterfrom
sjakobi/field-selection-simplifications

Conversation

@sjakobi

@sjakobi sjakobi commented Jul 30, 2019

Copy link
Copy Markdown
Collaborator

…as standardized in dhall-lang/dhall-lang#664.

Comment thread dhall/src/Dhall/Core.hs
Just v -> pure v
Nothing -> Field <$> (RecordLit <$> traverse loop kvs) <*> pure x
Project r_ _ -> loop (Field r_ x)
Prefer l (RecordLit kvs) -> case Dhall.Map.lookup x kvs of

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think what you want to do here is use a pattern guard, like this:

Prefer l (RecordLit kvs) | Just v <- Dhall.Map.lookup x kvs -> pure v
Prefer (RecordLit kvs) r_ | not (Dhall.Map.member x kvs) -> loop (Field r_ x)
…

The reason I suggest this is that if you handle the case for Nothing here then the normalizer won't attempt other simplifications.

Same comment for Dhall.Eval

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Are you sure? Actually the case for Nothing is also an important simplification and calls loop on the simplified expression…

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh whoops, I misread this. You're right

@mergify
mergify Bot merged commit cb38ba2 into master Jul 31, 2019
@mergify
mergify Bot deleted the sjakobi/field-selection-simplifications branch July 31, 2019 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants