From d2fb80c516fc1ff0acd7337ce63bb0eca96cec8b Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 8 Apr 2009 15:33:36 +0000 Subject: [PATCH] Added a foldM1 function to the Utils module --- common/Utils.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/Utils.hs b/common/Utils.hs index f598878..fcfbe20 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -393,3 +393,8 @@ liftWrapStateT wrap m (x, st') <- lift $ wrap (runStateT m st) put st' return x + +-- The foldM equivalent of foldl1: +foldM1 :: Monad m => (a -> a -> m a) -> [a] -> m a +foldM1 f (x:xs) = foldM f x xs +foldM1 _ [] = fail "Empty list in foldM1"