FSharp Functional Programming—Keywords
| CSharp-Online.NET:Articles |
| .NET Articles |
| © 2007 Robert Pickering |
Keywords
Most, if not all, programming languages have the concept of keywords. A keyword is a language token that the compiler reserves for special use. In F# you cannot use a keyword as an identifier name or a type name (I discuss types later in this chapter in "Defining Types"). The following are the F# keywords:
abstractlslandlsraslxorassertmatch memberasrmodbeginmoduleclassmutable namespacedefaultnewdelegatenulldoofdoneopendowncastordowntooverrideelserecendsigexceptionstaticfalsestructfinallythenfortofuntruefunctiontryiftypeinvalinheritwheninlineupcastinterfacewhilelandwithlor
The words listed next are not currently F# keywords but have been reserved for possible future use. It is possible to use them as identifiers or type names now, but the compiler will issue a warning if you do. If you care that your code is compatible with future versions of the compiler, then it is best to avoid using them. I will not use them in the examples in this book.
asyncmethodatomicmixinbreaknamespacecheckedobjectcomponentprocessconstpropertyconstraintprotectedconstructorpubliccontinuepuredecimalreadonlyeagerreturnenumsealedeventswitchexternalvirtualfixedvoidfunctorvolatileincludewhere
If you really need to use a keyword as an identifier or type name, you can use the double back quote syntax:
let ``class`` = "style"
The usual reason for doing this is when you need to use a member from a library that was not written in F# and that uses one of F#’s keywords as a name (you’ll learn more about using non-F# libraries in Chapter 4). The best practice is to avoid using keywords as identifiers if possible.
|

