Anonymous | Login | Signup for a new account 2017-09-19 13:40 CEST
 Main | My View | View Issues | Change Log | Roadmap

View Issue Details  Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005740OCamlstandard librarypublic2012-08-27 04:302016-12-09 09:22
Reporterfuruse
Assigned Tofrisch
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionwon't fix
PlatformOSOS Version
Product Version4.00.0
Target VersionFixed in Version
Summary0005740: Set should have a way to access the "middle" element and its left and right nodes.
DescriptionIt would be handy if Set provides an easy access to its binary tree structure:

val middle (* or whatever *) : t -> (t * elt * t) option

let middle = function
| Empty -> None
| Node (left, v, right, _) -> Some (left, v, right)

Currently we can have this function with very dirty workaround using iter/filter and side effects. Such a implementation by me recently broke by the change of search order of filter.

This function exposes the internal detail of Set, therefore it is against the spirit of the implementation encapsulation, but still it is very useful.
TagsNo tags attached.
Attached Files

 Relationships

 Notes xleroy (administrator) 2012-11-17 18:07 Hi Jun, This function is not just "against the spirit of the implementation encapsulation": it is not even a *function*, in that it can map equal sets (according to the "equal" predicate) to different results. So, pray tell, what is a good use case for this function? Something that you can't achieve just by using the current Set interface, esp. Set.fold? thelema (reporter) 2012-11-21 21:59 Batteries has a `Set.choose` value that just returns an arbitrary element of a non-empty set, which I find useful for initializing folds where there's no reasonable initial value to start the fold with (and just a pain to be constantly matching None) or recursive functions that repeatedly choose an element of the set and do some work that possibly removes other elements from the set before repeating. This pattern of removing an arbitrary element of a set became common enough that I added a `Set.pop : t -> elt * t` that returns an arbitrary element and a new set of the remaining elements. That said, neither of these breach the encapsulation, as long as you don't depend on any properties of the chosen element. berenger (reporter) 2013-01-04 08:34 Don't you need a find actually? Cf. http://caml.inria.fr/mantis/view.php?id=5864 [^] frisch (developer) 2016-12-09 09:22 No activity for a long time, and Xavier was not convinced by the proposal ==> marking as "won't fix" for now.

 Issue History Date Modified Username Field Change 2012-08-27 04:30 furuse New Issue 2012-11-15 19:43 doligez Status new => acknowledged 2012-11-17 18:07 xleroy Note Added: 0008520 2012-11-17 18:07 xleroy Status acknowledged => feedback 2012-11-21 21:59 thelema Note Added: 0008541 2013-01-04 08:34 berenger Note Added: 0008689 2016-12-09 09:22 frisch Note Added: 0016938 2016-12-09 09:22 frisch Status feedback => resolved 2016-12-09 09:22 frisch Resolution open => won't fix 2016-12-09 09:22 frisch Assigned To => frisch 2017-02-23 16:43 doligez Category OCaml standard library => standard library