Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# infix operators in c#?

In F# it is not uncommon to declare infix operators for binary operators. But how are they represented if we try to use them in C# Since there are no way of declaring infix operators in C#?

Toy Example

let ( .|. ) a b = a + b
like image 293
kam Avatar asked Dec 10 '20 06:12

kam


People also ask

What does ⟨F⟩ mean?

This sound is usually considered to be an allophone of /h/, which is pronounced in different ways depending upon its context; Japanese /h/ is pronounced as [ɸ] before /u/. In Welsh orthography, ⟨f⟩ represents /v/ while ⟨ff⟩ represents /f/. In Slavic languages, ⟨f⟩ is used primarily in words of foreign (Greek, Latin, or Germanic) origin.

What does the letter F mean in math?

In countries such as the United States, the letter "F" is defined as a failure in terms of academic evaluation. Other countries that use this system include Saudi Arabia, Venezuela, and the Netherlands. In the hexadecimal number system, the letter "F" or "f" is used to represent the hexadecimal digit fifteen (equivalent to 15 10 ).

What does F stand for in the Etruscan alphabet?

In the Etruscan alphabet, 'F' probably represented /w/, as in Greek, and the Etruscans formed the digraph 'FH' to represent /f/.

Is the letter F doubled at the end of words?

It is often doubled at the end of words. Exceptionally, it represents the voiced labiodental fricative / v / in the common word "of". F is the twelfth least frequently used letter in the English language (after C, G, Y, P, B, V, K, J, X, Q, and Z ), with a frequency of about 2.23% in words.


1 Answers

If you check the IL representation of your operator, you will see this:

 .method public static specialname int32
    op_DotBarDot(
      int32 a,
      int32 b
    ) cil managed

Unfortunately you won't be able to refer to this from C#. However you can add an attribute:

[<CompiledName("addop")>]
let ( .|. ) a b = a + b

Then you can just reference your F# dll from C# and call it via addop:

Console.WriteLine(global::Program.addop(1,2));

3

Process finished with exit code 0.

like image 75
s952163 Avatar answered Oct 17 '22 09:10

s952163