-
Notifications
You must be signed in to change notification settings - Fork 157
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
Feature: sconcat
and stimes
.
#580
Draft
kindaro
wants to merge
5
commits into
haskell:master
Choose a base branch
from
kindaro:feature-sconcat-stimes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
180645e
Add benchmarks for semigroup methods.
kindaro bf0c343
Add specialized implementation of semigroup methods.
kindaro 40ff68d
Check that `stimes` works right in corner cases.
kindaro 3c475cb
Make sure `stimes` works right in corner cases.
kindaro c314ce2
Be abstract of the implementation of `Integer`.
kindaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm somewhat cautious about potential overflow in
fromIntegral
. Let's throw an error ifText
is non-empty andn
does not fit intoInt
, same asbase
does forByteArray
: https://hackage.haskell.org/package/base-4.19.1.0/docs/src/Data.Array.Byte.html#stimesPolymorphic(We do not need to check that
len * n
fits intoInt
, because this is validated byData.Text.replicate
itself)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.
I do not follow why we should evaluate to the empty text when given a negative number but evaluate to an error when given a number that is bigger than
maxBound ∷ Int
, but your wish is my command.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.
However, we are not going to check the input in the same way as
base
because we should stay abstract. The way integers are represented is an implementation detail that had changed in the past and may change in the future. Supporting all versions of GHC we test with will need a lot of CPP without significant improvement in performance. So, I shall do an equality check instead of matching on the constructors ofInteger
.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.
Ah, I did not remember this peculiarity of
replicate
.I'd be in favor of
stimes
throwing an error on negative arguments, even ifreplicate
does not mind to swallow it silently. @Lysxia how do you feel about it?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.
Sounds good to me.
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.
This is the behaviour on lists:
So,
stimes
is not defined even whilereplicate
is defined on lists and negative numbers. We can do the same. Let me patch it up.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.
@Bodigrim So why would you be in favour of
stimes
throwing an error on negative arguments?@Lysxia So why does this sound good to you?
I should like to have the underlying reasoning recorded for posterity.
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.
Actually, this is a shocking revelation — the property checks of
text
overall compare the behaviour of functions onText
to their correspondents onString
, but the check forstimes
is missing both for strict and lazyText
. It would be consistent to add such a check forstimes
for both strict and lazyText
and adjust the definitions as needed for it to pass. @Bodigrim Should I add a check for lazyText
and make it pass, or should I only add a check for strictText
?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.
stimes
already throws an exception forn <= 0
. People haven't complained about it. Extending the definition forn = 0
is reasonable for a monoid.stimes
less partial and more similar toreplicate
(I think "replicate a string n times" is nonsense as a sentence in natural language, but I don't have a strong argument that code must follow natural language). Until someone makes a good case for extendingstimes
, throwing an exception for negative arguments is forward-compatible: we can extend the function later (it would only break code that catches the exception, a fishy thing to do). If we made it total now and changed our minds later, that would be a more breaking change.You can add the
stimes
test for strictText
now and add lazystimes
in another PR (small PR = good!)