FSharp Functional Programming—Keywords


Jump to: navigation, search
CSharp-Online.NET:Articles
.NET Articles

F# Functional Programming

© 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:

abstract lsl
and lsr
as lxor
assert match member
asr mod
begin module
class mutable namespace
default new
delegate null
do of
done open
downcast or
downto override
else rec
end sig
exception static
false struct
finally then
for to
fun true
function try
if type
in val
inherit when
inline upcast
interface while
land with
lor

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.

async method
atomic mixin
break namespace
checked object
component process
const property
constraint protected
constructor public
continue pure
decimal readonly
eager return
enum sealed
event switch
external virtual
fixed void
functor volatile
include where

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.


Previous_Page_.gif Next_Page_.gif




Personal tools

AbeBooks.com – Textbooks