Difference between revisions of "Haskell Quiz/FizzBuzz/Solution Heisenbug"

From HaskellWiki
Jump to: navigation, search
m (formatting)
m (use ++ from Prelude)
 
Line 3: Line 3:
 
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]
 
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]
 
where fizzbuzz n = (\case "" -> show n; fb -> fb)
 
where fizzbuzz n = (\case "" -> show n; fb -> fb)
(concat $ ["fizz" | n `rem` 3 == 0] <> ["buzz" | n `rem` 5 == 0])
+
(concat $ ["fizz" | n `rem` 3 == 0] ++ ["buzz" | n `rem` 5 == 0])

Latest revision as of 17:52, 31 July 2017

 {-# LANGUAGE LambdaCase #-}
 main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]
   where fizzbuzz n = (\case "" -> show n; fb -> fb)
                        (concat $ ["fizz" | n `rem` 3 == 0] ++ ["buzz" | n `rem` 5 == 0])