This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load "memo.fsx" | |
#load "fibonacci.fsx" | |
open memo | |
open fibonacci | |
open System.Diagnostics | |
let memo_fib = memoize fib | |
let memo_fib_tail = memoize fib_tail_recursion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module fibonacci | |
let rec fib n = | |
match n with | |
| 0 | 1 -> n | |
| n -> fib (n-1) + fib (n-2) | |
let fib_tail_recursion n = | |
let rec loop acc1 acc2 n = | |
match n with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module memo | |
open System.Collections.Generic | |
let memoize fn = | |
//let cache = new System.Collections.Generic.Dictionary<_,_>() | |
let cache = new Dictionary<_,_>() | |
printfn "counter: %A" cache.Count | |
fun x -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let memoize fn = | |
let cache = new System.Collections.Generic.Dictionary<_,_>() | |
printfn "counter: %A" cache.Count | |
fun x -> | |
printfn "%A is received" x | |
match cache.TryGetValue x with | |
| true, v -> v | |
| false, _ -> let v = fn (x) | |
cache.Add(x,v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let memoize fn = | |
let cache = new System.Collections.Generic.Dictionary<_,_>() | |
printfn "counter: %A" cache.Count | |
fun x -> | |
printfn "%A is received" x | |
match cache.TryGetValue x with | |
| true, v -> v | |
| false, _ -> let v = fn (x) | |
cache.Add(x,v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let memoize fn = | |
let cache = new System.Collections.Generic.Dictionary<_,_>() | |
printfn "counter: %A" cache.Count | |
fun x -> | |
printfn "%A is received" x | |
match cache.TryGetValue x with | |
| true, v -> v | |
| false, _ -> let v = fn (x) | |
cache.Add(x,v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fib n = | |
let rec loop acc1 acc2 n = | |
match n with | |
| 0 -> acc1 | |
| 1 -> acc2 | |
| _ -> loop acc2 (acc1 + acc2) (n - 1) | |
loop 0 1 n | |
fib 40 |> printfn "%A" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec fib n = | |
match n with | |
| 0 | 1 -> n | |
| n -> fib (n-1) + fib (n-2) | |
fib 40 |> printfn "%A" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type A() = class end | |
type B() = inherit A() | |
type C() = inherit A() | |
let evaluation (obj: A) = | |
match obj with | |
| :? B -> "It's a B" | |
| :? C -> "It's a C" | |
| :? A -> "It's a A" | |
| _ -> "nothing" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let detect1 x = | |
match x with | |
| 1 -> printfn "Found a 1!" | |
| (var1 : int) -> printfn "%d" var1 | |
let my_list = [0..9] | |
for i in my_list do detect1 i |
NewerOlder