-
Notifications
You must be signed in to change notification settings - Fork 789
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
List.transpose discards data instead of throwing an exception #6908
Comments
I agree that the behavior isn't correct. @PatrickMcDonald any insights or do you concur? FWIW I could see this going either direction, but given that we don't throw with lists to ease with composition scenarios (see creation of empty ranges or ranges with negative indices) I think it would be more expected to give I'd be happy to accept a PR that changes this behavior if there's no objections. |
Also worth noting that it is a breaking change to adjust List to have any changed behavior here, but given that it simply doesn't transpose anything I'd argue that it's worth changing. |
I agree this is a bug, and we should probably throw Note that this situation only occurs when an empty list is passed, the following will throw an exception > List.transpose [[true; true]; [false]; [false; false]];;
System.ArgumentException: The lists had different lengths.
list.[1] is 1 element shorter than list.[0]
Parameter name: list.[1]
at Microsoft.FSharp.Core.DetailedExceptions.invalidArgDifferentListLength[?](String arg1, String arg2, Int32 diff)
at Microsoft.FSharp.Primitives.Basics.List.transposeToFreshConsTail[a](FSharpList`1 cons, FSharpList`1 list, Int32 expectedCount)
at Microsoft.FSharp.Primitives.Basics.List.transpose[T](FSharpList`1 list)
at Microsoft.FSharp.Collections.ListModule.Transpose[T](IEnumerable`1 lists)
at <StartupCode$FSI_0008>.$FSI_0008.main@()
Stopped due to error |
* transpose does not throw when one of the elements is empty
When
List.transpose
is given a list containing an empty sublist, all sublists after the empty sublist are discarded.It's easier to explain by example:
compared to:
And:
though the Seq.transpose behavior is understandably quite different.
Provide the steps required to reproduce the problem:
List.transpose [[true; true]; []; [false; false]];;
Expected behavior
I would expect it to throw an exception just like the
Array.transpose
implementation, or maybe just filter out empty sublists, such thatList.transpose [[true; true]; []; [false; false]]
would return[[true; false]; [true; false]]
Actual behavior
List.transpose
discards any sublists after the first empty sublist (from what I can tell). For the particular case ofList.transpose [[true; true]; []; [false; false]]
it returns[[true]; [true]]
Known workarounds
Related information
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsi.exe
The text was updated successfully, but these errors were encountered: