Such an expression establishes a local function or value definition within the lexical scope of expr and has the same overall type as expr. In each case, the in token is optional if expr appears on a subsequent line and is aligned with the token let. In this case, a $in token is automatically inserted, and an additional syntax rule for lightweight syntax applies (§15.1.1) For example: let x = 1 x + x and let x, y = ("One", 1) x.Length + y and let id x = x in (id 3, id "Three") and let swap (x, y) = (y,x) List.map swap [ (1, 2); (3, 4) ] and let K x y = x in List.map (K 3) [ 1; 2; 3; 4 ] Function and value definitions in expressions are similar to function and value definitions in class definitions (§8.6.1.3), modules (§10.2.1), and computation expressions (§6.3.10), with the following exceptions: Function and value definitions in expressions may not define explicit generic parameters (§5.3). For example, the following expression is rejected: let f<'T> (x:'T) = x in f 3 Function and value definitions in expressions are not public and are not subject to arity analysis (§14.10). Any custom attributes that are specified on the declaration, parameters, and/or return arguments are ignored and result in a warning. As a result, function and value definitions in expressions may not have the ThreadStatic or ContextStatic attribute. Value Definition Expressions A value definition expression has the following form: let value-defn in expr where value-defn has the form: mutableopt accessopt pat typar-defnsopt return-typeopt = rhs-expr
Such an expression establishes a local function or value definition within the lexical scope of expr and has the same overall type as expr. In each case, the in token is optional if expr appears on a subsequent line and is aligned with the token let. In this case, a $in token is automatically inserted, and an additional syntax rule for lightweight syntax applies (§15.1.1) For example: let x = 1 x + x and let x, y = ("One", 1) x.Length + y and let id x = x in (id 3, id "Three") and let swap (x, y) = (y,x) List.map swap [ (1, 2); (3, 4) ] and let K x y = x in List.map (K 3) [ 1; 2; 3; 4 ] Function and value definitions in expressions are similar to function and value definitions in class definitions (§8.6.1.3), modules (§10.2.1), and computation expressions (§6.3.10), with the following exceptions: Function and value definitions in expressions may not define explicit generic parameters (§5.3). For example, the following expression is rejected: let f<'T> (x:'T) = x in f 3 Function and value definitions in expressions are not public and are not subject to arity analysis (§14.10). Any custom attributes that are specified on the declaration, parameters, and/or return arguments are ignored and result in a warning. As a result, function and value definitions in expressions may not have the ThreadStatic or ContextStatic attribute. Value Definition Expressions A value definition expression has the following form: let value-defn in expr where value-defn has the form: mutableopt accessopt pat typar-defnsopt return-typeopt = rhs-expr