From 0cd517a76d7120fdcb7fcb72bc17821d2e18e7aa Mon Sep 17 00:00:00 2001 From: David Binder <david.binder@uni-tuebingen.de> Date: Mon, 2 Jan 2023 17:45:44 +0100 Subject: [PATCH] Avoid partial list functions --- src/HpcUtils.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/HpcUtils.hs b/src/HpcUtils.hs index d4cee8d..a3ee5a6 100644 --- a/src/HpcUtils.hs +++ b/src/HpcUtils.hs @@ -15,10 +15,11 @@ dropWhileEndLE p = foldr (\x r -> if null r && p x then [] else x : r) [] grabHpcPos :: Map.Map Int String -> HpcPos -> String grabHpcPos hsMap srcspan = case lns of + [] -> error "grabHpcPos: invalid source span" [ln] -> take ((c2 - c1) + 1) $ drop (c1 - 1) ln - _ -> - let lns1 = drop (c1 - 1) (head lns) : tail lns + hd : tl -> + let lns1 = drop (c1 - 1) hd : tl lns2 = init lns1 ++ [take (c2 + 1) (last lns1)] in foldl1 (\xs ys -> xs ++ "\n" ++ ys) lns2 where -- GitLab