3

Possible Duplicate:
Using keywords as identifiers in F#

C# allows you prefix your variables with the @ keyword:

Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a legal identifier but if is not because it is a keyword.

I am wondering whether there is a similar construct in F#. If I recall correctly, even VB.NET provides a similar construct.

Community
  • 1
  • 1
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
  • 2
    Why would you ever want to name a variable after a keyword? It seems like that would create more confusion than it's worth. – 0x5f3759df Aug 24 '11 at 23:47
  • 1
    To keep convention throughout my API. If I want to name a variable type and I can't, I may want to try ``type`` instead of a ugly t, typ, type_, or whatever. – devoured elysium Aug 24 '11 at 23:49
  • 4
    @0x5: It's more likely that you'll have a variable is a reserved word in one language but not the one that the code was originally written in. If you need to access a library written in another language, you have to deal with this problem somehow. – JasonTrue Aug 24 '11 at 23:55
  • 3
    This has been discussed a few times: [Using keywords as identifiers in F#](http://stackoverflow.com/questions/6639688/using-keywords-as-identifiers-in-f) and [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) – Tomas Petricek Aug 25 '11 at 00:06

1 Answers1

9

use quotes:

let rec ``let rec`` () = ``let rec`` ()
desco
  • 16,642
  • 1
  • 45
  • 56