-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Generalization of Seq.group #12495
Comments
I don't see why not personally, since it shouldn't come at a performance cost and doesn't change anything for predicates that work on equivalence classes (like equality), and assuming it's thoroughly documented :) |
Hi! This sounds possibly OK, but I would like to see what new definition of I note that we seem to have no test of the function |
I assume it would be something like this (NOT tested): let rec take_adjacent p x xs () =
match xs() with
| Nil ->
Nil
| Cons (y, ys) ->
if p x y then Cons (x, take_adjacent p y ys) else Nil
let rec drop_adjacent p x xs () =
match xs() with
| Nil ->
Nil
| Cons (y, ys) as node ->
if p x y then drop_adjacent p y ys () else node
let rec group p xs () =
match xs() with
| Nil ->
Nil
| Cons (x, xs) ->
Cons (cons x (take_adjacent p x xs), group p (drop_adjacent p x xs)) |
Indeed, this seems to be what I had in mind. |
What should we discuss now? No one seems to object to this feature request. Unfortunately, I would not have time to make a PR in the next several weeks, but it seems the PR should involve:
Did I miss something? |
An extension of the documentation of the function Also, perhaps we should decide whether the auxiliary functions |
I prefer not to make those auxiliary functions public yet---at least I don't feel my code above has a nice interface. I might wish to have |
The
Seq.group
function introduced by #10583 (and also Haskell'sgroup
) has the following behavior where elements are compared against the first element in each group instead of their adjacent elements: (I will writeSeq.t
in the list notation.)However, I feel this is not very useful. I would hope that the predicate was used on immediately adjacent pairs. That is,
When the functional argument is an equality, the two behaviors will agree, and when they do not agree, I believe the second behavior is more useful. The current specification says nothing about non-equality arguments, so this feature request is a generalization. The downside is that this will depart from the corresponding function in Haskell. I am tagging @c-cube and @fpottier for their original contribution in #10583.
The text was updated successfully, but these errors were encountered: