From 25798c7cc22adbe8a9e1809bc7ce0edfd21bb63b Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 10 Oct 2011 23:12:17 -0400 Subject: [PATCH] Haskell 001 with guards --- haskell/e001.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/haskell/e001.hs b/haskell/e001.hs index 7e0d147..b4760e8 100644 --- a/haskell/e001.hs +++ b/haskell/e001.hs @@ -7,13 +7,10 @@ import Text.Printf multiples :: (Integral a) => a -> a -multiples max = - if max < 3 then - 0 - else - if (max `mod` 5 == 0 || max `mod` 3 == 0) then - max + multiples (max - 1) - else multiples (max - 1) +multiples max + | max < 3 = 0 + | (max `mod` 5 == 0) || (max `mod` 3 == 0) = max + multiples (max - 1) + | otherwise = multiples (max - 1) main = do printf "Sum of multiples below 10: %d\n" (multiples 9 :: Int)