Hi! I've been diving into functional programming lately. Really neat stuff! So here is my first Haskell program (worthy of being called a program?)
fizz :: Int -> Bool
fizz x = if x `mod` 3 == 0 then True else False
buzz :: Int -> Bool
buzz x = if x `mod` 5 == 0 then True else False
fizzbuzz = [if x `mod` 15 == 0 then
"FizzBuzz"
else if fizz x then
"Fizz"
else if buzz x then
"Buzz"
else
show x | x <- [1..100]]
This program is the FizzBuzz program described here: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
Second version with the guidance of a post from that page I linked:
fizz :: Int -> Bool
fizz x = if mod x 3 == 0 then True else False
buzz :: Int -> Bool
buzz x = if mod x 5 == 0 then True else False
fizzbuzz :: Int -> [Char]
fizzbuzz x | mod x 15 == 0 = "FizzBuzz"
| fizz x = "Fizz"
| buzz x = "Buzz"
fizzbuzz x = show x
To run: map fizzbuzz [1 .. 100]