Roughly speaking that what a set is in F#, obviously there are no repeated items, but not sure if this is important if you're list is sorted. Haven't profiled it so don't know what fast it is, but it is immutable and based on a binary tree.

Cheers,

Rob

By on 11/7/2008 4:25 AM ()

Thanks. That's interessting - but I have to specify a sort order function.

I think I will give it a try and later post my solution.

Best regards,

Steffen

By on 11/7/2008 4:59 AM ()

Hi,

There's a Set.Make function in the PowerPack. It's marked for OCaml Compatibility, but I don't know what's the F# way. Example of use:

1
2
3
4
5
6
7
// Set.Make returns a set of functions
let AbsSet = Set.Make(fun x y -> compare (abs x) (abs y))

let set_of_list l =
    List.fold_left (fun s e -> AbsSet.add e s) AbsSet.empty l

set_of_list [-2; 5; 2; 4]

A set has no repeated values. Thus, this set contains 3 elements (-2, 5 and 4).

Laurent

By on 11/7/2008 7:05 AM ()

Thanks. This is perfect.

Steffen

By on 11/7/2008 7:53 AM ()

Thanks for the help.

I put all the information together and blogged two small articles about it.

See "A immutable sorted list in F# - part I" and part II if

By on 11/10/2008 5:20 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