Skip to content

Infix operators as first-class functions #2052

Closed

Description

@Dretch

Infix operators can't be used like normal functions. Instead of:

std::sort::merge_sort(<=, some_strs)

one must write:

std::sort::merge_sort({|a, b| a <= b}, some_strs)

It would be nice to not have to write the lamda.

Activity

  1. brson commented on Mar 26, 2012

    @brson
    Contributor

    This doesn't directly address your issue but most types have standard comparison functions defined, like uint::le. There's an additional problem with them though, that they are usually defined with by-value parameters, but generic functions expect by-ref parameters. We could also define something like core::univ that defines all the universal operators over generic types, like eq, ne, lt, gt, le, ge.

  2. catamorphism commented on Apr 19, 2012

    @catamorphism
    Contributor

    I agree with @Dretch that this is a nice idea (I used it all the time in Haskell), but in general, we're trying to remove features from the language rather than add them. If you are passionate about it, though, please open a new bug and follow the RFC process: https://github.com/mozilla/rust/wiki/Note-RFC-process

    Closing this for now.

  3. added a commit that references this issue on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions