You're right about how they go through the map. The signatures are also different (seed and function are flipped).

1
2
3
4
> List.fold (-) 0 [1;2;3];;
val it : int = -6
> List.foldBack (-) [1;2;3] 0;;
val it : int = 2

Fold is a left fold, foldBack is a right fold. More info: [link:en.wikipedia.org]

By on 6/24/2009 10:36 PM ()

I did not check it for the List.fold/foldBack, but here what I am getting for the Map functions:

for Map.fold help gives me this:

var fold : ('Key->'Value->'State->'State) -> Map<'Key,'Value> -> 'State -> 'State

Fold over the bindings in the map

Full name: Microsoft.FSharp.Compatibility.Map.fold

for Map.foldBack it shows this:

var foldBack : ('Key->'T->'State->'State) -> Map<'Key,'T> -> 'State -> 'State

Fold over the bindings in the map

Full name: Microsoft.FSharp.Collections.MapModule.foldBack

somehow Map.fold and Map.foldBack point to different namespaces

By on 6/25/2009 8:24 AM ()

Yep, it is confirmed.

I gave it the fully qualified name and got the function I wanted Microsoft.FSharp.Collections.map.fold.

Now the question is who is this Comaptibility guy and why he is getting in the way?

By on 6/25/2009 8:26 AM ()

The compatibility Map.fold will be removed in the next F# release (beta2).

In the mean time, when referencing the F# Power Pack and using the function, perhaps add something like the following at the top of your file to clarify

module Map =

let fold f z m = Microsoft.FSharp.Collections.Map.fold f z m

Kind regards

Don

By on 6/25/2009 2:07 PM ()

try using (fun a k v -> v::a) and (fun k v a -> v::a) as your folder function and you would see the difference

By on 6/24/2009 7:00 PM ()
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