Abusing Laziness and HO
The following two examples (ab)use Haskell’s laziness and higher order features to allow concise functions of recursive functions.
> module HigherOrder where
> import Data.List (nubBy)
- All the prime numbers
> primes :: [Int]
> primes = nubBy (((>1).).gcd) [2..]
- All fibonacci
> fibs :: [Int]
> fibs = 0:1:(zipWith (+) fibs (tail fibs))