In [ ]:

```
count' :: [a] -> Int -> Int
count' [] result = result
count' (first:rest) result = count' rest (result + 1)
```

In [ ]:

```
count :: [a] -> Int
count list = count' list 0
```

In [ ]:

```
allNumbersStartingAt n = n : allNumbersStartingAt (n+1)
take 5 (allNumbersStartingAt 0)
```

```
{.haskell .fragment}
→ [0,1,2,3,4]
```

In [ ]:

```
take 11 (cycle ['S','O','S', '-'])
```

In [ ]:

```
divideByTen :: Fractional a => a -> a
divideByTen = (/ 10)
```

`elem`

¶In [ ]:

```
isUpperCase :: Char -> Bool
isUpperCase = (`elem` ['A' .. 'Z'])
```

In [ ]:

```
applyTwice :: (a -> a) -> a -> a
applyTwice f x = f (f x)
```

- First parameter is a function of type
`(a -> a)`

- Second parameter is a value of type
`a`

In [ ]:

```
applyTwice (+3) 10
applyTwice ("Hello, " ++) "who is there?"
applyTwice (3:) [1]
```

In [ ]:

```
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' f [] bs = []
zipWith' f as [] = []
zipWith' f (a:as) (b:bs) = f a b : zipWith' f as bs
```

In [ ]:

```
zipWith' (+) [1, 2, 3] [1, 2, 3]
zipWith' (*) (replicate 4 3) [1..]
zipWith' max [3,7,2] [4,1,6]
zipWith' (++) ["James T. ", "", "Nyota "] ["Kirk", "Spock", "Uhura"]
```

In [ ]:

```
fibs = 0 : 1 : zipWith' (+) fibs (tail fibs)
```

- Calculate the Ns number of the Fibonacci sequence
- First hit on Google for
*haskell fibonacci*: The Fibonacci sequence - HaskellWiki

In [ ]:

```
fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
```

In [ ]:

```
map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f (x:xs) = f x : map f xs
```

In [ ]:

```
map ("Beam me up, " ++) ["Kirk", "Spock", "Scotty"]
map (replicate 3) [1, 2, 3]
map fst [('A', 'B'), ('C', 'D'), ('E', 'F')]
map snd [('A', 'B'), ('C', 'D'), ('E', 'F')]
```

In [ ]:

```
filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
filter' p (x:xs)
| p x = x : filter' p xs
| otherwise = filter' p xs
```

In [ ]:

```
filter (>3) [1,5,3,2,1,6,4,3,2,1]
filter even [1,5,3,2,1,6,4,3,2,1]
filter (`elem` ['a'..'z']) "Beam me up, Scotty!"
filter (`elem` ['A'..'Z']) "Beam me up, Scotty!"
```