on master help sign in
Get rid of warning, throw specific error in impossible case
commitf63020a52133a76a7a6964dc6d19d94067920c94 authorEvan Czaplicki <info@elm-lang.org> dateTue 9 Feb 2016, 18:16 (11 years ago) parentba5bfd2
1 file changed+16−11
src/Optimize/DecisionTree.hs+16−11
src/Optimize/DecisionTree.hs+16−11
@@ -431,19 +431,24 @@ addWeights toWeight paths =
431431
432432
433433bests :: [(Path, Int)] -> [Path]
434−bests ( (headPath, headWeight) : weightedPaths ) =
435− let
436− gatherMinimum acc@(minWeight, paths) (path, weight) =
437− if weight == minWeight then
438− (minWeight, path : paths)
434+bests allPaths =
435+ case allPaths of
436+ [] ->
437+ error "Cannot choose the best of zero paths. This should never happen."
439438
440− else if weight < minWeight then
441− (weight, [path])
439+ (headPath, headWeight) : weightedPaths ->
440+ let
441+ gatherMinimum acc@(minWeight, paths) (path, weight) =
442+ if weight == minWeight then
443+ (minWeight, path : paths)
442444
443− else
444− acc
445− in
446− snd (List.foldl' gatherMinimum (headWeight, [headPath]) weightedPaths)
445+ else if weight < minWeight then
446+ (weight, [path])
447+
448+ else
449+ acc
450+ in
451+ snd (List.foldl' gatherMinimum (headWeight, [headPath]) weightedPaths)
447452
448453
449454-- PATH PICKING HEURISTICS