Skip to content

PR#6279: add Set.map to stdlib#553

Merged
alainfrisch merged 1 commit intoocaml:trunkfrom
gasche:set-map
May 2, 2016
Merged

PR#6279: add Set.map to stdlib#553
alainfrisch merged 1 commit intoocaml:trunkfrom
gasche:set-map

Conversation

@gasche
Copy link
Member

@gasche gasche commented Apr 18, 2016

stdlib/set.mli Outdated
with respect to the ordering over the type of the elements. *)

val map: (elt -> elt) -> t -> t
(** [map f s] creates a new set with elements [f a0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace "creates a new set with elements" by "is a set with elements" (describe the value denoted by the expression).

stdlib/set.mli Outdated

val map: (elt -> elt) -> t -> t
(** If the elements of [s] are [a0],[a1],..[aN], then the elements
of [map f s] are [f a0],[f a1]... [f aN].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer the documentation pattern "[map f s] is ..." it directly tells you how to read the occurence of such an expression in a program.

@gasche gasche force-pushed the set-map branch 2 times, most recently from 4c9b7b7 to 21006fb Compare April 19, 2016 01:20
@damiendoligez damiendoligez added this to the 4.04 milestone Apr 19, 2016
val equal : t -> t -> bool
val subset : t -> t -> bool
val iter : f:(elt -> unit) -> t -> unit
val map : (elt -> elt) -> t -> t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be labeled ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks.

@alainfrisch
Copy link
Contributor

  • I would either make it explicit that the function must be the physical identity on mapped elements, or test with Ord.comparerather than ==.
  • What about providing filter_map (with a function `'a -> 'a option') as well?

@gasche
Copy link
Member Author

gasche commented Apr 25, 2016

Using Ord.compare would be wrong if map intentionally update parts of the structure that are not taken into account by the comparison function (for example the values have a unique identifier, and compare uses them only, but the function updates another field). I'll update the specification.

@gasche
Copy link
Member Author

gasche commented Apr 25, 2016

I updated the branch.

@hcarty
Copy link
Member

hcarty commented Apr 25, 2016

If we're going to add filter_map here it would be nice to add it to the rest of the appropriate stdlib modules as well.

@gasche
Copy link
Member Author

gasche commented Apr 25, 2016

I think I'm not going to work on filter_map as part of this pull-request.

@alainfrisch alainfrisch merged commit 3fe0cb1 into ocaml:trunk May 2, 2016
@vicuna vicuna mentioned this pull request Mar 14, 2019
mshinwell added a commit to mshinwell/ocaml that referenced this pull request Jul 12, 2021
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
…view (ocaml#578)

Co-authored-by: Sabine Schmaltz <[email protected]>
Co-authored-by: Christine Rose <[email protected]>
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Clarifications/rewrites on the "First Hour With OCaml" tutorial.

* add a section about using the OCaml Playground
* mention what # means in the code examples
* spell out what's happening more clearly for beginners

---------

Signed-off-by: Christine Rose <[email protected]>
Co-authored-by: Christine Rose <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants