Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use F# exponentiation operator (**) in prefix notation?

Tags:

f#

With most operators in F# I can use prefix or infix notation, for example:

let x = a + b

is equivalent to

let x = (+) a b

This does not work for the exponentation operator ** however, because the parenthesised version is treated as a comment. That is, (*this is a comment*) is F# syntax for a comment, so (**) is treated as an empty comment.

let x = a ** b   // a raised to b

let x = (**) a b // empty comment, followed by function a applied to b

Is there an escape character I can use or is this simply a strange quirk of the language?

like image 578
Oenotria Avatar asked Sep 02 '15 20:09

Oenotria


People also ask

How do you use F in Python?

Strings in Python are usually enclosed within double quotes ( "" ) or single quotes ( '' ). To create f-strings, you only need to add an f or an F before the opening quotes of your string. For example, "This" is a string whereas f"This" is an f-String.

What does F {} mean in Python?

Also called “formatted string literals,” f-strings are string literals that have an f at the beginning and curly braces containing expressions that will be replaced with their values.

What are F-strings and how do you use it?

F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code, an f-string is a literal string, prefixed with 'f', which contains expressions inside braces.

Why F string is used in Python?

Python f-strings provide a faster, more readable, more concise, and less error prone way of formatting strings in Python. The f-strings have the f prefix and use {} brackets to evaluate values.


1 Answers

Try using spaces between the parentheses, as pointed by kvb in the comments:

let x = ( ** ) a b
like image 156
2 revs Avatar answered Sep 22 '22 23:09

2 revs