Skip to content

Change nested record update syntax and fix bug with depth > 2#2580

Merged
paf31 merged 3 commits into
purescript:masterfrom
LiamGoodacre:fix/nested-update
Jan 29, 2017
Merged

Change nested record update syntax and fix bug with depth > 2#2580
paf31 merged 3 commits into
purescript:masterfrom
LiamGoodacre:fix/nested-update

Conversation

@LiamGoodacre

Copy link
Copy Markdown
Member

No description provided.

let path' = path ++ [key]
updates = goLayer path' <$> M.toList branch
accessor = foldr Accessor val path'
accessor = foldl (flip Accessor) val path'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the bug fix. Apparently I never tested with depth > 2. It would generate the accessor in reverse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it's just a little thing, but foldl' is preferrable to foldl in almost all cases

l.bar.baz == r.bar.baz &&
l.bar.qux == r.bar.qux
l.bar.qux.lhs == r.bar.qux.lhs
l.bar.qux.rhs == r.bar.qux.rhs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oops missing &&

@LiamGoodacre

Copy link
Copy Markdown
Member Author

For #1807

parseHole = Hole <$> holeLit

parsePropertyUpdate :: TokenParser (NonEmpty PSString, Expr)
parsePropertyUpdate :: TokenParser [(NonEmpty PSString, Expr)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just parse the tree structure directly here? It seems like now you're turning it back and forth into a list of paths.

@paf31

paf31 commented Jan 16, 2017

Copy link
Copy Markdown
Contributor

I like the new syntax, thanks!

@LiamGoodacre

Copy link
Copy Markdown
Member Author

I'm pretty much rewriting it from scratch now. 😛
wrapLambdaM is so much nicer with a traversable functor of expressions.

@LiamGoodacre

LiamGoodacre commented Jan 17, 2017

Copy link
Copy Markdown
Member Author

Now that I'm building the tree earlier, I can't use Map - I need information about the order when processing the wildcards (they correspond to lambdas from left-to-right).

@paf31 paf31 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, thanks! Is anything else left to do here?

@LiamGoodacre

Copy link
Copy Markdown
Member Author

The parse error is bad when you have duplicate keys:

[1/1 ErrorParsingModule] src/Main.purs:8:14

  8  m = {foo: 0} {foo = 1, foo = 2}


  Unable to parse module:
  unexpected {
  expecting indentation at column 1 or end of input

In the parser I wrote an error saying "Duplicate key in record update: " ++ show key. But I'm not sure how to make it show that instead?

@LiamGoodacre

Copy link
Copy Markdown
Member Author

The parseUpdaterBody is behind a try at https://github.com/purescript/purescript/pull/2580/files#diff-476f52dcaa59ca2e52c4e867fda6a60fR441
I've tried moving the try inside parseUpdaterBodyFields before we build the tree, and it works for the first level, but not nested.

@paf31

paf31 commented Jan 19, 2017

Copy link
Copy Markdown
Contributor

Ah ok. So solving this won't be trivial, but it's possible. We'd have to combine records and record updates into a single parser, I think.

@kritzcreek

kritzcreek commented Jan 22, 2017

Copy link
Copy Markdown
Member

I just tried to compile slamdata with the current master for benchmarking purposes and the parser fails on:

    collapse  Card.Model  Array Card.Model  Maybe Card.Model
    collapse parent child = case parent, child of
      CM.Draftboard { layout }, [ cm@CM.Draftboard { layout: subLayout } ] → do
        cursor ← Pane.getCursorFor (Just deckId) layout
        layout' ← Pane.modifyAt (const subLayout) cursor layout
        pure $ CM.Draftboard { layout: layout' }

with:

[1/1 ErrorParsingModule] src/SlamData/Workspace/Eval/Persistence.purs:385:52

  385        CM.Draftboard { layout }, [ cm@CM.Draftboard { layout: subLayout } ] → do
                                                          
  Unable to parse module:
  unexpected {
  expecting ::, operator, , or ]

I guess it's related to the recent accessor chain parser changes? If it doesn't belong here lmk and I'll open a separate issue.

@LiamGoodacre

Copy link
Copy Markdown
Member Author

@kritzcreek would you also be able to try this with the latest commit in this pull request?

@kritzcreek

Copy link
Copy Markdown
Member

@LiamGoodacre Still get the same error with this branch.

@LiamGoodacre

Copy link
Copy Markdown
Member Author

@kritzcreek actually I think what you're seeing is related to #2559
This bit is causing the failure: cm@CM.Draftboard { layout: subLayout }

@kritzcreek

Copy link
Copy Markdown
Member

Thanks for the help cm@(CM.Draftboard { layout: subLayout }) fixes the compiler error! Might want to add that to a migration guide for the next release.

@natefaubion

Copy link
Copy Markdown
Contributor

That seems like a bug, doesn't it? Parens aren't required like that for operator aliases.

@LiamGoodacre

Copy link
Copy Markdown
Member Author

@kritzcreek @natefaubion Could we move this conversation to either #2559 or a new issue, thanks :)

@paf31 paf31 merged commit 32faa76 into purescript:master Jan 29, 2017
@LiamGoodacre LiamGoodacre deleted the fix/nested-update branch January 29, 2017 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants