Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Map.{alter,alter_add} #8223

Closed
vicuna opened this issue Jul 24, 2003 · 0 comments
Closed

Add Map.{alter,alter_add} #8223

vicuna opened this issue Jul 24, 2003 · 0 comments

Comments

@vicuna
Copy link

vicuna commented Jul 24, 2003

Original bug ID: 1771
Reporter: @yakobowski
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2017-02-20T11:28:07Z)
Resolution: duplicate
Priority: normal
Severity: feature
Category: standard library
Duplicate of: #7309
Related to: #2748
Monitored by: "Boris Yakokobowski"

Bug description

Full_Name: Boris Yakobowski
Version: 3.07+beta 1
OS: Linux
Submission from: lcultra.macs.hw.ac.uk (137.195.27.64)

(C'est un wish, pas un bug)

Serait-il envisageable de rajouter la fonction suivante, ou une autre
approchante, dans le foncteur Map.Make ?
val alter_add : ('a option -> 'a) -> key -> 'a t -> 'a t
(** [alter_add f x m] returns a map containing the same bindings as
[m], except for the binding of [x], which is [f None)] if [x] was
not previously bound, and [f (Some y)] if [x] was previously
bound to [y]. *),
qui est plus ou moins équivalent à un find suivi d'un add conditionnel, mais en
une seule traversée. C'est particulièrement utile quand on utilise des
dictionnaires de dictionnaires, et qu'on veut ajouter une valeur au dictionnaire
référencé par la 1ère clé.

Une alternative (ou plutôt une fonction complémentaire) serait
val alter: ('a -> 'a) -> key -> 'a t -> 'a t
(** [alter f x m] returns a map containing the same bindings as
[m], except for the binding of [x] which becames [f x] if x
was present in [m] *)

En plus mineur, serait-il possible d'avoir une interface non fonctorielle pour
Map et Set, qui utilise Pervasives.compare par défaut (comme Hashtbl pour hash)
? Évidemment c'est beaucoup de duplication de code, mais je ne me rappelle pas
avoir utilisé une fonction de comparaison autre que Pervasives.compare...

--
Boris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants