Skip to content

Rewrote null check to use mempty #68

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

Merged
merged 2 commits into from
Oct 8, 2016
Merged

Conversation

Risto-Stevcev
Copy link
Contributor

No description provided.

@@ -72,7 +73,7 @@ foreign import _toChar :: (forall a. a -> Maybe a)

-- | Returns `true` if the given string is empty.
null :: String -> Boolean
null s = length s == zero
null = eq mempty
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well use "" here and avoid the dictionary lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I knew there must've been a reason why mempty isn't being used here. Is a JSON lookup amortized O(1)?

@garyb
Copy link
Member

garyb commented Oct 8, 2016

I'm actually baffled as to why it was implemented the way it was! The length approach is how it'd have to be implemented in Haskell (due to type String = [Char]), but comparison with "" would always be better for us.

It might be better to implement this without point-free though, as string equality can be inlined if it's fully applied: null s = s == "".

@garyb
Copy link
Member

garyb commented Oct 8, 2016

Thanks!

@garyb garyb merged commit 6843c74 into purescript:master Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants