From 3f7d328d356c75c0ae57c67eb64fb5337361cce7 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 11 Dec 2022 13:51:04 +0200 Subject: Only evaluate fn arg when immediately calling function with that arg --- src/Utils.hs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/Utils.hs') diff --git a/src/Utils.hs b/src/Utils.hs index 01ecb17..1eabd72 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -376,3 +376,9 @@ foldStackMessage (LException st) = case st of where fmtPos p = if useless p then "" else (" at " ++ p) useless p = "nonsense" `L.isPrefixOf` p || length p == 0 + +fold1M :: (Monad m) => (a -> a -> m a) -> [a] -> m a +fold1M _ (x:[]) = return x +fold1M f (x:y:xs) = do ret <- f x y + fold1M f (ret : xs) +fold1M _ [] = error $ "fold1M of empty list" -- cgit v1.3