Brand new for Haskell. I play with a Fibonacci sequence to learn the basics of the language, and I cannot find an idiomatic way to do something.
The Fibonacci sequence can be defined as follows:
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
(This is already pretty cool). Then I want to use the sequence to approximate the ratio of Gold (Phi). So:
ratios = zipWith (/) (tail fibs) fibs
- A list of the best and best Phi approximations. Let's say I want to get the first value when the list has “stabilized” under the given epsilon threshold. (i.e. the difference between two consecutive relationship values is less than epsilon). I can see how I will do it in an imperative language (using indexes), but how would I do it idiomatically in Haskell?
(Do I need to use the following list? But how?)
diffs = zipWith (-) ratios (tail ratios)