O'Reilly logo

Professional F# 2.0 by Richard Minerich, Talbott Crowell, Aaron C. Erickson, Ted Neward

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Lexical Structure

WHAT'S IN THIS CHAPTER?

  • Understanding basic syntax

  • Defining values and identifiers

In any language, some basic lexical ideas have to be laid down before programmers can begin to understand the concepts behind the language — questions such as "What makes a comment?" or "What is allowed in identifier names?," although intrinsically boring in many ways, have to be defined before any further progress into the language's structure and form.

F#'s lexical structure derives strongly from its immediate ancestor, OCaml, which is itself a derivative of the pure functional language ML. This means that for the most part, although F# strives to be .NET-friendly in terms of its syntax, the C# and Visual Basic developer can find a number of new and interesting syntactic ideas, some of which will be surprising. Fortunately, most of those will be pleasant surprises because much of the syntax is less restrictive than the other .NET languages offered from Microsoft.

COMMENTS

The easiest place to begin with any language is a simple definition of what makes a comment (meaning, syntax that the compiler will ignore during processing). F# supports three different styles of comments:

  • Multi-line comments using the (* and *) delimiters, such as:

    (* This is
    a multi-line
    comment *)

    Note that multi-line comments nest, meaning that the multi-line comment will only be terminated when the number of end-comment pairs match the number of begin-comment pairs preceding it.

  • Single-line comments using ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required