Verbose Syntax

There are two forms of syntax available for many constructs in the F# language: verbose syntax and lightweight syntax. The verbose syntax is not as commonly used, but has the advantage of being less sensitive to indentation. The lightweight syntax is shorter and uses indentation to signal the beginning and end of constructs, rather than additional keywords like begin, end, in, and so on. The default syntax is the lightweight syntax. This topic describes the syntax for F# constructs when lightweight syntax is not enabled. Verbose syntax is always enabled, so even if you enable lightweight syntax, you can still use verbose syntax for some constructs. You can disable lightweight syntax by using the #light "off" directive.

Table of Constructs

The following table shows the lightweight and verbose syntax for F# language constructs in contexts where there is a difference between the two forms. In this table, angle brackets (<>) enclose user-supplied syntax elements. Refer to the documentation for each language construct for more detailed information about the syntax used within these constructs.

Language construct Lightweight syntax Verbose syntax
compound expressions ```xml ``` ``` ; ```
nested `let` bindings ``` let f x = let a = 1 let b = 2 x + a + b ``` ``` let f x = let a = 1 in let b = 2 in x + a + b ```
code block ``` ( ) ``` ``` begin ; ; end ```
`for...do` ``` for counter = start to finish do ... ``` ``` for counter = start to finish do ... done ```
`while...do` ``` while do ... ``` ``` while do ... done ```
`for...in` ``` for var in start .. finish do ... ``` ``` for var in start .. finish do ... done ```
`do` ``` do ... ``` ``` do ... in ```
record ``` type = { } ``` ``` type = { } with end ```
class ``` type () = ... ``` ``` type () = class ... end ```
structure ``` [] type = ... ``` ``` type = struct ... end ```
discriminated union ``` type = | ... | ... ... ``` ``` type = | ... | ... ... with end ```
interface ``` type = ... ``` ``` type = interface ... end ```
object expression ``` { new with } ``` ``` { new with end } ```
interface implementation ``` interface with ``` ``` interface with end ```
type extension ``` type with ``` ``` type with end ```
module ``` module = ... ``` ``` module = begin ... end ```

See also