You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
List.map3 misleading error when lists of different lengths #6897
map3ToFreshConsTail operates on t1,t2,t3, recursively pops heads off, and fails if at least one but not all of the input lists are empty. It then reports the lengths of the current lists, not the lengths of the original lists.
A fix:
try
map3ToFreshConsTail cons f t1 t2 t3
cons
with_->
invalidArg3ListsDifferent "list1""list2""list3" xs1.Length xs2.Length xs3.Length
That comes at the cost of incurring three length checks to report the error, each of which are O(n). I'd suggest altering map3ToFreshConstTail to take tuples of (currentLength, list) for the t1, t2, t3 parameters to enable fast error reporting.
Any performance considerations here should be benchmarked, as we don't know what the actual performance of either approach will be. Though I would prefer incurring the cost on the error.
Activity
baronfel commentedon May 29, 2019
That comes at the cost of incurring three length checks to report the error, each of which are
O(n). I'd suggest alteringmap3ToFreshConstTailto take tuples of(currentLength, list)for the t1, t2, t3 parameters to enable fast error reporting.charlesroddie commentedon May 29, 2019
Is fast error reporting important? More important not to make valid cases slower surely?
cartermp commentedon May 29, 2019
Any performance considerations here should be benchmarked, as we don't know what the actual performance of either approach will be. Though I would prefer incurring the cost on the error.
charlesroddie commentedon May 29, 2019
A faster version of this would be to add a single (alreadyCut:int) parameter to map3ToFreshConstTail to add to all the lengths in the error case.