Generating Fibonacci series in F#
Posted
by photo_tom
on Stack Overflow
See other posts from Stack Overflow
or by photo_tom
Published on 2010-05-16T22:30:46Z
Indexed on
2010/05/16
22:50 UTC
Read the original article
Hit count: 169
I'm just starting to learn F# using VS2010 and below is my first attempt at generating the Fibonacci series. What I'm trying to do is to build a list of all numbers less than 400.
let fabList =
let l = [1;2;]
let mutable a = 1
let mutable b = 2
while l.Tail < 400 do
let c = a + b
l.Add(c)
let a = b
let b = c
My first problem is that on the last statement, I'm getting an error message "Incomplete structured construct at or before this point in expression" on the last line. I don't understand what I'm doing wrong here.
While this seems to be an obvious way to build the list in a fairly efficient way (from a c++/C# programmer), from what little I know of f#, this doesn't seem to feel to be the right way to do the program. Am I correct in this feeling?
© Stack Overflow or respective owner