File: highlight.fs

package info (click to toggle)
kate4 4%3A4.14.3-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 33,264 kB
  • ctags: 14,143
  • sloc: xml: 199,778; cpp: 116,560; python: 9,947; ansic: 994; ruby: 397; sh: 370; asm: 166; makefile: 151; php: 137; jsp: 128; haskell: 116; f90: 99; ml: 75; perl: 63; erlang: 54; sed: 48; awk: 40; yacc: 37; tcl: 29; lisp: 24
file content (24 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(* Fibonacci Number formula from Wikipedia's F# article *)
let rec fib n =
    match n with
    | 0 | 1 -> n
    | _ -> fib (n - 1) + fib (n - 2)
 
(* An alternative approach - a lazy recursive sequence of Fibonacci numbers *)
let rec fibs = Seq.cache <| seq { yield! [1; 1]                                  
                                  for x, y in Seq.zip fibs <| Seq.skip 1 fibs -> x + y }
 
(* Another approach - a lazy infinite sequence of Fibonacci numbers *)
let fibSeq = Seq.unfold (fun (a,b) -> Some(a+b, (b, a+b))) (1,1)
 
(* Print even fibs *)
[1 .. 10]
|> List.map     fib
|> List.filter  (fun n -> (n % 2) = 0)
|> printlist
 
(* Same thing, using sequence expressions *)
[ for i in 1..10 do
    let r = fib i
    if r % 2 = 0 then yield r ]
|> printlist