Repository navigation
Core implementation of List.contains #20847
|
I'm wondering if it's something that's been overlooked or a type optimization I'm not aware of. As I see it currently, the core implementation of List.contains is: Notice that equalityCheck closes over the element being looked for. However the recursive function definition also carries that value around (argument e) but doesn't actually use it. |
Replies: 1 comment
|
Good catch, that It doesn't break anything, and the cost is basically one extra argument per call, so you won't notice it in practice. It's still dead code though, so it could just be: let rec contains xs1 = contains source Probably worth opening a small PR for it, cleanups like this usually get accepted pretty quickly. |
Good catch, that
eparameter isn't doing anything.equalityCheckalready closes overvalue, so passing it down the recursion is redundant. It looks like a leftover from an earlier version rather than a deliberate optimization.It doesn't break anything, and the cost is basically one extra argument per call, so you won't notice it in practice. It's still dead code though, so it could just be:
let rec contains xs1 =
match xs1 with
| [] -> false
| h1 :: t1 -> equalityCheck h1 || contains t1
contains source
Probably worth opening a small PR for it, cleanups like this usually get accepted pretty quickly.