The docs on OptimizedClosures say to avoid using it, so why use it?

[link:research.microsoft.com]

This works fine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let map5 f l1 l2 l3 l4 l5 = 
    let rec map5 f l1 l2 l3 l4 l5 acc = 
        match l1,l2,l3,l4,l5 with
        | [],[],[],[],[] -> List.rev acc
        | (h1::t1),(h2::t2),(h3::t3),(h4::t4),(h5::t5) -> let x = f h1 h2 h3 h4 h5 in map5 f t1 t2 t3 t4 t5 (x :: acc)
        | _ -> failwith "the lists had different lengths"
    map5 f l1 l2 l3 l4 l5 []

let list1 = [0;1;2;3;4;5]
let list2 = [0;1;2;3;4;5]
let list3 = [0;1;2;3;4;5]
let list4 = [0;1;2;3;4;5]
let list5 = [0;1;2;3;4;5]
let output = map5 (fun x1 x2 x3 x4 x5 -> x1+x2+x3+x4+x5) list1 list2 list3 list4 list5
printfn "%A" output
By on 3/26/2009 9:49 AM ()

Because I thought I had to use it or there was some special trick to this. Thanks for the correction; the function really can be passed just like any argument.

I am going to start trying to write my functions in a more general way like this.

I didn't know the inner recursive function could have the same name as the outer non-recursive function without confusion.

By on 3/26/2009 10:46 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper