-
Notifications
You must be signed in to change notification settings - Fork 297
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
Simplify Line type in Quasi module, always use NonEmpty #1231
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
made a note that the version is going to be 2.11.1.1, which i'm planning on releasing today
@@ -2,6 +2,8 @@ | |||
|
|||
## 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No probs I will shift this up 👍
persistent/Database/Persist/Quasi.hs
Outdated
pure $ Line (parseIndentationAmount txt) toks | ||
parseLine txt = do | ||
parsedTokens <- NEL.nonEmpty (tokenize txt) | ||
pure $ Line (parseIndentationAmount txt) parsedTokens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 😄
lowestIndent | ||
:: Functor f | ||
=> Foldable f | ||
=> Functor g | ||
=> f (Line' g) | ||
=> f Line | ||
-> Int | ||
lowestIndent = minimum . fmap lineIndent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
).
@@ -212,7 +214,7 @@ main = hspec $ do | |||
it "mid-token quote in later token" $ | |||
parseLine "foo bar baz=(bin\")" `shouldBe` | |||
Just | |||
( Line 0 | |||
( Line 0 $ nonEmptyOrFail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
it "recognizes comments" $ do | |
let text = "Foo\n x X\n-- | Hello\nBar\n name String" | |
let expected = | |
Line { lineIndent = 0, tokens = asTokens ["Foo"] } :| | |
[ Line { lineIndent = 2, tokens = asTokens ["x", "X"] } | |
, Line { lineIndent = 0, tokens = [DocComment "Hello"] } | |
, Line { lineIndent = 0, tokens = asTokens ["Bar"] } | |
, Line { lineIndent = 1, tokens = asTokens ["name", "String"] } | |
] | |
preparse text `shouldBe` Just expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool works for me!
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:
@since
declarations to the Haddockstylish-haskell
on any changed files..editorconfig
file 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
Line
where 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 theskipEmpty
function, asNonEmpty
guarantees us nonempty-ness 👍