Simplify Line type in Quasi module, always use NonEmpty#1231
Conversation
parsonsmatt
left a comment
There was a problem hiding this comment.
looks great!
made a note that the version is going to be 2.11.1.1, which i'm planning on releasing today
| ## 2.12.1.0 | ||
|
|
||
| * [#1231](https://github.com/yesodweb/persistent/pull/1231) | ||
| * Simplify Line type in Quasi module, always use NonEmpty |
There was a problem hiding this comment.
2.12.1.0 has already been released, this is going to get bundled in with 2.12.1.1
There was a problem hiding this comment.
No probs I will shift this up 👍
| pure $ Line (parseIndentationAmount txt) toks | ||
| parseLine txt = do | ||
| parsedTokens <- NEL.nonEmpty (tokenize txt) | ||
| pure $ Line (parseIndentationAmount txt) parsedTokens |
| => f (Line' g) | ||
| => f Line | ||
| -> Int | ||
| lowestIndent = minimum . fmap lineIndent |
There was a problem hiding this comment.
Can we specialize this function, too? I feel like we can get away with specializing this, possibly even to NonEmpty which would make it even safer (mimumum [] = undefined).
| parseLine "foo bar baz=(bin\")" `shouldBe` | ||
| Just | ||
| ( Line 0 | ||
| ( Line 0 $ nonEmptyOrFail |
There was a problem hiding this comment.
For the test suite, we could enable OverloadedLists, and then we can use list literal syntax for NonEmpty a - it's a gross kludge to write [] :: NonEmpty Int, but, lmao, it does make the test syntax nicer.
| asTokens :: [T.Text] -> [Token] | ||
| asTokens = fmap Token | ||
| nonEmptyOrFail :: [a] -> NonEmpty a | ||
| nonEmptyOrFail = maybe failure id . NEL.nonEmpty |
There was a problem hiding this comment.
there's the horribly namedNEL.fromList :: [a] -> NonEmpty a unless by some act of grace it was removed
There was a problem hiding this comment.
buuut if we just use list literal syyntax I think this can go away
| Just | ||
| [ Line 0 [Token "Foo"] | ||
| , Line 0 [DocComment "Hello"] | ||
| ] |
There was a problem hiding this comment.
The switch to using OverloadedLists caused this to give an ambiguous type error:
• Couldn't match expected type ‘GHC.Exts.Item (t0 Line)’
with actual type ‘Line’
The type variable ‘t0’ is ambiguous
• In the expression: Line 0 [Token "Foo"]
In the first argument of ‘Just’, namely
‘[Line 0 [Token "Foo"], Line 0 [DocComment "Hello"]]’
In the second argument of ‘shouldBe’, namely
‘Just [Line 0 [Token "Foo"], Line 0 [DocComment "Hello"]]’
|
236 | [ Line 0 [Token "Foo"]
| ^^^^^^^^^^^^^^^^^^^^
I've opted to actually just delete this test, this function is being tested already with the other tests here (the one above and below it), and also in the context of multiple lines, in tests like this one:
persistent/persistent/test/main.hs
Lines 538 to 547 in 813fe42
|
Hey I wasn't finished! 😂 sorry, maybe I shouldn't have pushed that stuff up. I will have another PR shortly, it should still fit in fine as a follow on I think :) |
|
Oh, shoot! I've already released as 2.11.1.1 😅 Try to mark a PR as a draft if it's not ready yet? |
|
Yeah its no big deal, what I meant was I wasn't done with the review updates, I've still yet to remove the |
Before submitting your PR, check that you've:
@sincedeclarations to the Haddockstylish-haskellon any changed files..editorconfigfile for details)After submitting your PR:
(unreleased)on the ChangelogThis is a followon from #1206 that addresses the TODO comment here:
persistent/persistent/Database/Persist/Quasi.hs
Lines 546 to 555 in 53359c8
Following recent refactoring there is not actually any instance of
Linewhere the contents of the list are notNonEmpty, so this PR changes that type to always useNonEmpty, rather than being polymorphic, which greatly simplifies a lot of the code aroundLine, and means we can also get rid of theskipEmptyfunction, asNonEmptyguarantees us nonempty-ness 👍