- Could someone tell what is wrong with this code. I would expect the

result to be [2]. Thanks -- David

module IntSet =

Set.Make(struct type t = int let compare = compare end)

open IntSet

let set_map f = fold (fun x s -> (add (f x) s)) empty

elements (set_map ((+) 1) (singleton 1))

- : IntSet.elt list = [1] - --- In ocaml_beginners@yahoogroups.com, "dvanhorn_at_uvm" <david@v...>

wrote:> Could someone tell what is wrong with this code. I would expect the

Dumb question. Sorry for the noise. I had the order of parameters to

> result to be [2]. Thanks -- David

>

> module IntSet =

> Set.Make(struct type t = int let compare = compare end)

> open IntSet

> let set_map f = fold (fun x s -> (add (f x) s)) empty

>

> elements (set_map ((+) 1) (singleton 1))

> - : IntSet.elt list = [1]

fold switched up.

David - From: "dvanhorn_at_uvm" <david@...>

Subject: "ocaml_beginners"::[] set_map

Date: Thu, 01 Jul 2004 17:13:22 -0000

> Could someone tell what is wrong with this code. I would expect the

The order of the arguments of fold is wrong. You should use

> result to be [2]. Thanks -- David

>

> module IntSet =

> Set.Make(struct type t = int let compare = compare end)

> open IntSet

> let set_map f = fold (fun x s -> (add (f x) s)) empty

>

> elements (set_map ((+) 1) (singleton 1))

> - : IntSet.elt list = [1]

let set_map f s0 = fold (fun x s -> add (f x) s) s0 empty

^^

The set applied to the iterator comes to the second position. In

general, I would advise you to avoid overuse of Currying.

--

Yamagata Yoriyuki