Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using keywords as identifiers in F#

In C#, I can do the following:

int @private = 15; 

And in VB.NET, I can do the following:

Dim [Private] As Integer = 15 

I am wondering if there is a way in F# to use reserved keywords as identifiers, like there is in VB.NET and C#?

like image 266
Icemanind Avatar asked Jul 10 '11 06:07

Icemanind


People also ask

Can we use keyword as an identifier?

Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier.

Can we use keywords as a identifier in Python?

Keywords cannot be used as identifiers.

Why keywords Cannot be used as identifiers in Python?

In Python, keywords are the reserved names that are built-in to Python, so a keyword cannot be used as an identifier - they have a special meaning and we cannot use them as identifier names. Special symbols like !, @, #, $, %, etc. are not allowed in identifiers. Python identifiers cannot only contain digits.

What are keywords and identifiers with example?

No punctuation or special symbol except 'underscore' is used. Examples of keywords are: int, char, if, while, do, class etc. Examples of identifiers are: Test, count1, high_speed, etc.


1 Answers

Given section 3.4 of the F# 2.0 spec:

Identifiers follow the specification below. Any sequence of characters that is enclosed in double-backtick marks (`` ``), excluding newlines, tabs, and double-backtick pairs themselves, is treated as an identifier.

I suspect you can put it in backticks:

``private`` 

I haven't tried it though.

like image 113
Jon Skeet Avatar answered Sep 19 '22 21:09

Jon Skeet