@@ -382,13 +382,12 @@ span p (x::xs) =
382382break : (a -> Bool) -> List a -> (List a, List a)
383383break p = span (not . p)
384384
385−%assert_total
386385split : (a -> Bool) -> List a -> List (List a)
387386split p [] = []
388387split p xs =
389388 case break p xs of
390389 (chunk, []) => [chunk]
391− (chunk, (c :: rest)) => chunk :: split p rest
390+ (chunk, (c :: rest)) => chunk :: split p (assert_smaller xs rest)
392391
393392partition : (a -> Bool) -> List a -> (List a, List a)
394393partition p [] = ([], [])
@@ -432,26 +431,23 @@ sorted (x::xs) =
432431 Nil => True
433432 (y::ys) => x <= y && sorted (y::ys)
434433
435−%assert_total -- can't work this out, because in the case which is lifted out
436− -- y::ys and x::xs are bigger than the inputs...
437434mergeBy : (a -> a -> Ordering) -> List a -> List a -> List a
438435mergeBy order [] right = right
439436mergeBy order left [] = left
440437mergeBy order (x::xs) (y::ys) =
441− case order x y of
442− LT => x :: mergeBy order xs (y::ys)
443− _ => y :: mergeBy order (x::xs) ys
438+ if order x y == LT
439+ then x :: mergeBy order xs (y::ys)
440+ else y :: mergeBy order (x::xs) ys
444441
445442merge : Ord a => List a -> List a -> List a
446443merge = mergeBy compare
447444
448−%assert_total
449445sort : Ord a => List a -> List a
450446sort [] = []
451447sort [x] = [x]
452−sort xs =
453− let (x, y) = split xs in
454− merge (sort x) (sort y) -- not structurally smaller, hence assert
448+sort xs = let (x, y) = split xs in
449+ merge (sort (assert_smaller xs x))
450+ (sort (assert_smaller xs y)) -- not structurally smaller, hence assert
455451 where
456452 splitRec : List a -> List a -> (List a -> List a) -> (List a, List a)
457453 splitRec (_::_::xs) (y::ys) zs = splitRec xs ys (zs . ((::) y))