38

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#?

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • 1
    possible duplicate of [F#: Implementing interface with function name the same as the keyword begin](http://stackoverflow.com/questions/3864034/f-implementing-interface-with-function-name-the-same-as-the-keyword-begin) – Brian Jul 10 '11 at 08:08

1 Answers1

46

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.

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    Good find Jon. I tried it out by doing `let \`\`let\`\` = 75` and `System.Console.WriteLine(\`\`let\`\`)` it worked. So know we all know. Thanks for the help – Icemanind Jul 10 '11 at 06:58
  • 1
    This does work although it is syntactically very tedious. I recommend keeping such names private. – ChaosPandion Jul 10 '11 at 06:59
  • 3
    @ChaosPandion - I know. I agree. I am converting a library over to F# and it has an interface in it with a reserved keyword and changing the name of the interface would mean changing a bunch of other classes too, some of which, I don't have the source code. But if I could avoid it, I would. Trust me – Icemanind Jul 10 '11 at 07:01
  • I find this issue, but this not work with tags (F# 4.0, mono): ``Tags`` Err FS1219 – mamcx Jun 11 '15 at 15:06
  • @mamcx: I'm not sure how to parse that comment, I'm afraid - but perhaps this is something you should file as a bug on F#? – Jon Skeet Jun 11 '15 at 15:07
  • I mean that if using the word tags the backticks not work, it get FS1219 – mamcx Jun 11 '15 at 15:12
  • 1
    @mamcx: Well, I can't see an F# 4.0 specification yet - I would definitely report it to the F# folks. – Jon Skeet Jun 11 '15 at 15:37