GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Core implementation of List.contains · dotnet/fsharp · Discussion #20847

Core implementation of List.contains #20847

Answered by LeandroCustodio2002
davidgrenier asked this question in Q&A
Core implementation of List.contains #20847
@davidgrenier davidgrenier
Oct 22, 2026 · 1 comment
Answered by LeandroCustodio2002 Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

davidgrenier
Oct 22, 2026

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:

[<CompiledName("Contains")>]
let inline contains value source =
    let equalityCheck listElement =
        value = listElement

    let rec contains e xs1 =
        match xs1 with
        | [] -> false
        | h1 :: t1 -> equalityCheck h1 || contains e t1

    contains value source

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.

You must be logged in to vote
All reactions
Answered by LeandroCustodio2002 Oct 22, 2026

Good catch, that e parameter isn't doing anything. equalityCheck already closes over value, 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.

View full answer

Replies: 1 comment

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

LeandroCustodio2002
Oct 22, 2026

Good catch, that e parameter isn't doing anything. equalityCheck already closes over value, 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.

You must be logged in to vote
All reactions
  • 👍 2
  • 👎 1
0 replies
Answer selected by davidgrenier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
@davidgrenier @LeandroCustodio2002
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.