Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.

いいコードが書けるようになったら随時書き直す。

# FizzBuzz

FizzBuzz.hs
```fizzBuzz :: Integer -> String
fizzBuzz n
| n <= 0        = show n
| mod n 15 == 0 = "Fizz Buzz"
| mod n 5 == 0  = "Buzz"
| mod n 3 == 0  = "Fizz"
| otherwise     = show n
```

すべての条件に`n > 0`をANDでつけるのはイマイチ..

FizzBuzz.hs
```fizzBuzz :: Integer -> String
fizzBuzz n
| mod n 15 == 0 = "Fizz Buzz"
| mod n 5 == 0  = "Buzz"
| mod n 3 == 0  = "Fizz"
| n >= 1         = show n
```

ローカルで使う関数はwhere句の中で定義する。

FizzBuzz.hs
```fizzBuzz :: Integer -> String
fizzBuzz n | n >= 1 = f n
where
f n
| mod n 15 == 0 = "Fizz Buzz"
| mod n 5 == 0  = "Buzz"
| mod n 3 == 0  = "Fizz"
| otherwise     = show n
```

## 後で理解できるようになりたいコード

```import Control.Monad (guard)
import Data.Maybe (fromMaybe)
import Data.Monoid ((<>))

main :: IO()
main = mapM_ (putStrLn . fizzbuzz) [1..100]

fizzbuzz :: Integer -> String
fizzbuzz = let (d ~> s) n = s <\$ guard (n `mod` d == 0)
in fromMaybe . show <*> 3 ~> "Fizz" <> 5 ~> "Buzz"
```

# Fibonacci

Fibonacci.hs
```fibonacci :: Integer -> Integer
fibonacci 0 = 0
fibonacci 1 = 1
fibonacci n = fibonacci (n - 1) + fibonacci (n - 2)
```

# reverse

```reverse' xs = f xs []