Generating Fibonacci series in F#

后端 未结 11 1915
南方客
南方客 2020-12-31 02:58

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

11条回答
  •  一整个雨季
    2020-12-31 03:40

    This function "fib" will return a list of Fibonacci numbers that are not greater than 500

    let rec fib a b =
        let current = a + b
        match current with
        | _ when current >= 500 -> []
        | _ -> current :: fib b current 
    
    let testFib = fib 1 2;;
    

提交回复
热议问题