{-# LANGUAGE BangPatterns #-} module M where foo :: [Int] -> Maybe Int foo = go 1 0 where go :: Int -> Int -> [Int] -> Maybe Int go !i !n [] = Just n go i n (x:xs) | i < 10 = go (i+1) (n+x) xs | otherwise = Nothing