Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9317407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:52:15+00:00 2026-06-19T02:52:15+00:00

based on: Is possible to define same-named operator for different argument count? I want

  • 0

based on: Is possible to define same-named operator for different argument count?

I want to define some operator like + but let call -|- for example to have

let a = -|- 1
let b = 1 -|- 1
let c = 1 -|- 1 1 1 1

At least 2 first lines will work for + but how can I declare own operator like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:52:16+00:00Added an answer on June 19, 2026 at 2:52 am

    I don’t think there is a straightforward way to do this in general. You could probably use an inline operator with a mix of static member constraints to cover some of the cases that you want, but I don’t think it will be very elegant.

    For some operator names, you can however define a separate prefix and infix version, which covers the first two cases:

    // Prefix version of the operator (when you write e.g. '+. 10')
    let (~+.) a = a * 10
    // Infix version of the operator (when you write e.g. '1 +. 10')
    let (+.) a b = a + b
    
    // Sample use
    +. 10
    10 +. 20
    

    You still won’t be able to write 10 +. 20 30 40, because then you’d need an overloaded infix operator.

    It is worth noting that you cannot do this for all operator names. Here is a syntax definition from the F# specification of the allowed operator names for infix operators:

    infix-or-prefix-op :=
          +, -, +., -., %, &, &&

    prefix-op :=
          infix-or-prefix-op
          ~ ~~ ~~~ (and any repetitions of ~)
          !OP (except !=)

    PS: I’m not generally a big fan of custom operators – in some cases, they are nice, but they are difficult to discover (you do not see them in the IntelliSense) and unless you’re using standard ones for numerical computing, it is often difficult to understand what they mean. So I would maybe consider other approaches…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Is it possible to push a value into array based on its key but
Is it possible to grab a list of memcached key based on some regex?
I want to define a Lambda Expression with an out parameter. Is it possible
The idea is to create a DOM-like tree. But there are some restrictions, that
Is it possible to use django class based generic views with a ManyToManyField relation?
Is it possible to create a variable name based on the value of a
Is it possible to disable or enable subgrid based on the selected value when
Is it possible to change the assembly name based on the project configuration? I
is it possible to ask parent for its refered collection_name based on one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.