-
Notifications
You must be signed in to change notification settings - Fork 8
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
Should we throw an exception for TaskSeq.zip when the sequences are of unequal length? #32
Comments
Of relevance, for infinite sequences, this example is relevant: https://stackoverflow.com/questions/7226004/seq-zip-in-f-may-require-seemingly-extra-sequence-element-to-complete. This post gives these two examples (adjusted for clarity):
Basically: if you have an infinite sequence, and you have a filter that returns only two elements of the infinite set, then, combining that with another sequence using The cause being: we need to "peek", and (at least one of) the sequence(s) will try to Currently, the way this is implemented in F# is such that it is deterministic: if one of the two sequences exhibits this behavior (i.e. |
/cc @gusty, what do you think? I tend towards raising an exception, as we do know whether there is a "next" item (the only reason we wouldn't know this is by using the Haskell way, explained in the above SO post, but that makes this operation non-deterministic to argument order) and it feels like this was an oversight in F# Core. But at the same time, parity is a good thing as well. TLDR, we have these options:
Basically the same questions would apply to |
I would definitely align with the mechanism for |
I’m considering adding a shadowed function set that can be opened, that have an overload that takes a I’m still a little on the fence about parity with F#. They made a mistake (IMO) by not having the same behaviour for all collection types (where that makes sense and doesn’t require potential extra side effects). But there’s also the “principle of least surprise”. Hmm, yeah, ultimately I guess I have to bite the bullet and go for parity. |
I agree in that they made a mistake, but to me the mistake was on Of interest, in F#+ there is |
I agree with you there. I mean: the different collections should have parity in behaviour. And if you can get away without exceptions it’s generally better, but then that should have applied to all of them.
|
This has now been solved in #102. |
While writing tests for #31, I started pondering this ☝️.
For comparison, F# throws an
ArgumentException
forArray.zip
andList.zip
, but not forSeq.zip
. Most likely, this is because "getting the next item" can have an unwanted side effect, so instead, they choose to stop processing as soon as one of the sequences is exhausted.Arguably, such side effect can still happen. I.e., for
zip
we have to callMoveNextAsync
, which will give us abool
that tells us whether we reached the end of the sequence. But, if the first sequence still has items, but the second sequence is exhausted, the side effect of the first sequence for "one item past the last" has already happened.In fact, I think the
Seq.zip
in F# should probably come with a warning. What if each item is "getting a web page of several megabytes"? AFAIK, there's nopeek
function that would potentially tell me, without side effects, that a sequence is exhausted.Edit: linking the discussion in the F# repo: dotnet/fsharp#14121
The text was updated successfully, but these errors were encountered: