// One read on volatileMutableValue, which may not be duplicated. let (a3, b3) = volatileMutableValue a1, b1, a2, b2, a3, b3 member x.WriteValues() = // One read on mutableValue, which may be duplicated according // to ECMA CLI spec. let (a2, b2) = mutableValue // One write on mutableValue. mutableValue <- (a2 + 1, b2 + 1) // One read on volatileMutableValue, which may not be duplicated. let (a3, b3) = volatileMutableValue // One write on volatileMutableValue. volatileMutableValue <- (a3 + 1, b3 + 1) let obj = ClassContainingMutableData() Async.Parallel [ async { return obj.WriteValues() }; async { return obj.WriteValues() }; async { return obj.ReadValues() }; async { return obj.ReadValues() } ] Zero Values Some types have a zero value. The zero value is the“default” value for the type in the CLI execution environment. The following types have the following zero values: For reference types, the null value. For value types, the value with all fields set to the zero value for the type of the field. The zero value is also computed by the F# library function Unchecked.defaultof<ty>. Taking the Address of an Elaborated Expression When the F# compiler determines the elaborated forms of certain expressions, it must compute a “reference” to an elaborated expression expr, written AddressOf(expr, mutation). The AddressOf operation is used internally within this specification to indicate the elaborated forms of address-of expressions, assignment expressions, and method and property calls on objects of variable and value types. The AddressOf operation is computed as follows: If expr has form path where path is a reference to a value with type byref<ty>, the elaborated form is &path.
Special Attributes and Types This chapter describes attributes and types that have special significance to the F# compiler. Custom Attributes Recognized by F# The following custom attributes have special meanings recognized by the F# compiler. Except where indicated, the attributes may be used in F# code, in referenced assemblies in F#, or in assemblies that are authored in other CLI languages. Attribute Description System.ObsoleteAttribute [<Obsolete(...)>] Indicates that the construct is obsolete and gives a warning or error depending on the settings in the attribute. This attribute may be used in both F# and imported assemblies. System.ParamArrayAttribute [<ParamArray(...)>] When applied to an argument of a method, indicates that the method can accept a variable number of arguments. This attribute may be used in both F# and imported assemblies. System.ThreadStaticAttribute [<ThreadStatic(...)>] Marks a mutable static value in a class as thread static. This attribute may be used in both F# and imported assemblies. System.ContextStaticAttribute [<ContextStatic(...)>] Marks a mutable static value in a class as context static. This attribute may be used in both F# and imported assemblies. System.AttributeUsageAttribute [<AttributeUsage(...)>] Specifies the attribute usage targets for an attribute. This attribute may be used in both F# and imported assemblies. System.Diagnostics.ConditionalAttribute [<Conditional(...)>] Emits code to call the method only if the corresponding conditional compilation symbol is defined. This attribute may be used in both F# and imported assemblies. System.Reflection.AssemblyInformationalVersionAttribute [<AssemblyInformationalVersion(...)>] Attaches additional version metadata to the compiled form of the assembly. This attribute may be used in both F# and imported assemblies. System.Reflection.AssemblyFileVersionAttribute [<AssemblyFileVersion(...)>] Attaches file version metadata to the compiled form of the assembly. This attribute may be used in both F# and imported assemblies.
automatic generalization, 13 AutoOpen attribute, 221 AutoOpenAttribute, 305 AutoSerializable attribute, 151, 153, 155 base type, 55 basic types abbreviations for, 305 block expressions, 104 bprintf function, 93 byref arguments, 273 byref pointers, 67 byref-address-of expression, 98 case names, 152 characters, 28 class types, 155 additional fields in, 161 members in, 159 class/end tokens, 155 classes, 53 CLI methods, 276 CLI pointer types, 306 CLIEvent attribute, 181, 186 CLIMutable, 152 comments, 25, 277 compare function, 193 CompareTo, 192 comparison attributes, 190 comparison constraint, 51 ComparisonConditionalOn constraint dependency, 190 compatibility features, 315 compilation order, 222 CompilationRepresentation attribute, 182, 206 COMPILED compilation symbol, 23, 224 compiler directives, 225 computation expression, 76 condensation, 269 Conditional attribute, 255 conditional compilation, 26, 255 ML compatibility and, 315 conditional expressions, 104 constant expressions, 68 constants with measure annotations, 197 constrained types, 47 constraints, 47 comparison, 51 current inference, 45 default constructor, 49 delegate, 50 dependency of, 190 enumeration, 50 equality, 51 equational, 257 explicit declaration of, 52 flexible type, 113 inflexible type, 113 member, 259 member, 48 nullness, 48, 58, 93, 258 reference type, 50 simple, 258 solving, 257 struct, 49, 258 subtype, 47, 257 unmanaged, 51 ContextStatic attribute, 110, 208 control flow expressions, 104 copy-and-update record expression, 72 curried form, 175 custom attributes effect on signature checking, 233 in type definitions, 145 CustomComparison attribute, 190 CustomEquality attribute, 189 CustomOperationAttribute, 80 declarations base type, 54 interface, 54 default initialization, 58 DefaultValue attribute, 161 definition expressions, 109 definitions recursive, 261 delayed expression, 76 delegate constraint, 50 delegate implementation expression, 96 delegate type, 166 delegates, 53 deterministic disposal expression, 112 directives #load, 224 #nowarn, 224 compiler, 225 lexical, 225 line, 33 preprocessing, 26 dispatch slot checking, 75, 273 dispatch slot inference, 75, 271 dispatch slots, 273 do statements, 157 in modules, 210
static, 158 done token, 108 dynamic coercion expressions, 114, 124 dynamic type-test expressions, 113, 123 elif branch, 105 else branch, 105 entry points, 229 EntryPoint attribute, 229 enum types, 165 enumerable extraction, 106 enums, 53 equality attributes, 189 equality constraint, 51 EqualityConditionalOn constraint dependency, 190 evaluation of active pattern results, 96 of AddressOf expressions, 125 of array expressions, 122 of definition expressions, 123 of dynamic coercion expressions, 124 of dynamic type-test expressions, 123 of field lookups, 121 of for loops, 123 of function applications, 121 of function expressions, 122 of method applications, 121 of object expressions, 122 of record expressions, 122 of sequential execution expressions, 124 of try-finally expressions, 125 of try-with expressions, 125 of union cases, 121 of value references, 120 of while loops, 123 event types, 311 events, 180 exception definitions, 166 exceptions, 302 execution of F# code, 226 expression splices, 116 expressions address-of, 98 application, 94 array. See array expression array sequence, 92 assertion, 109 assignment, 102 block, 104 builder, 76 checking of, 65 computation, 65, 76 conditional, 104 constant, 68 delayed, 76 delegate implementation, 96 deterministic disposal, 112 dynamic coercion, 114 dynamic type-test, 113 elaborated, 66 evaluation of, 117 for loop, 107 function, 73 function and value definitions, 109 list, 70 list sequence, 92 lookup, 99 member constraint invocation, 101 name resolution in, 237 null, 93 object. See object expressions object construction, 96 operator, 97, 98 parenthesized, 104 pattern-matching, 105 precedence in, 41 quoted, 67, 114 range, 65, 91 record construction, 71 recursive, 112 reraise, 108 sequence, 90 sequence iteration, 106 sequential conditional, 105 sequential execution, 104 shortcut and, 105 shortcut or, 105 slice, 100 static coercion, 113 syntactical elements of, 61 try-finally, 108 try-with, 108 tuple, 69 type-annotated, 113 while-loop, 107 extension members, 168 defined by C#, 169 field lookups, 121 fields additional, in classes, 161 name resolution for labels, 243 filename extensions, 23
ML compatibility and, 317 files implementation, 222 signature. See signature files flexibility, 255 flexible types, 150 floating type variable environment, 45 for loop, 107 for loops, 123 format strings, 93 fprintf function, 93 fresh type, 45 function applications, 121 function definition expressions, 109 function definitions, 157, 261, 263 ambiguous, 261 in modules, 207 static, 158 function expressions, 73, 122 function values, 14 functions active pattern, 133 undentation of, 285 GeneralizableValue attribute, 209 generalization, 55, 267 generic types, 267 GetHashCode, 192 GetSlice, 100 guarded rules, 139 hash function, 193 hashing, 188 hidden tokens, 278 identifiers, 26 local names for, 211 long, 39 OCaml keywords as, 315 replacement of, 33 if statement, 104 if/then/else expression undentation of body, 285 immutability, 13 immutable collection types, 311 implementation files anonymous, 223 contents of, 222 implementation members, 183 import declarations, 210 in token, 109 indentation, 277 incremental, 285 indexer properties, 173 inference arity, 274 dispatch slot, 271 inference variables, 55 infix operators, 41 Information-rich Programming, 19 inherit declaration, 156, 162 initialization, 58 of objects, 155 static, 226 instance members, 171 compilation as static method, 182 integer literals, 69 INTERACTIVE compilation symbol, 23, 224 interface type definitions, 162 interface types, 56, 186 interface/end tokens, 162 interfaces, 53 internal accessibility, 211 internal type abbreviations, 150 InternalsVisibleTo attribute, 212 intrinsic extensions, 168 IsLikeGroupJoin, 81 IsLikeJoin, 81 JoinConditionWord, 81 keywords OCaml, 315 symbolic, 30 kind anonymous, 148 kind of type definition, 53 lazy computations, 311 libraries CLI base, 305 F# base, 305 lightweight syntax, 11, 277 balancing rules for, 282 disabling, 317 parsing, 280 rules for, 277 line directives, 33 list expression, 70 list sequence expression, 92 list type, 310 Literal attribute, 208 literals integer, 69 numeric, 31 string, 28 lookup expression-qualified, 247
basic arithmetic, 306 bitwise, 307 checked arithmetic, 310 default definition of, 97 exception, 309 function pipelining and composition, 308 generic equality and comparison, 307 infix, 41 input and output handles, 309 math, 307 ML compatibility and, 317 names of, 35 object transformation, 308 overloaded conversion functions, 309 pair, 309 precedence of, 41 prefix, 41 splicing, 116 symbolic, 30, 40 option type, 311 OptionalArgument attribute, 178 overflow checking, 310 parallel execution, 118 ParamArray conversion, 251 parenthesized expressions, 104 pattern matching, 14 pattern-matching expression, 105 pattern-matching function, 106 patterns, 129 active, 133 array, 138 as, 135 conjunctive, 136 cons, 136 dynamic type-test, 137 guarded rules for, 139 literal, 132 name resolution for, 241 named, 131 null, 139 record, 138 simple constant, 130 type-annotated, 136 union case, 131 variable, 131 wildcard, 135 pointer, byref, 67 precedence differences from OCaml, 316 of function applications, 286 of type applications, 287 prefix operators, 41 preprocessing directives, 26 printf, 312 printf function, 93 private accessibility, 211 private type abbreviations, 150 ProjectionParameterAttribute, 81 properties custom operation, 80 property members, 170, 172, 183 public accessibility, 208, 211 quotations, 312 quoted expression, 114 quoted expressions, 67 range expressions, 91 rec, 157 record construction expression, 71 record expressions evaluation of, 122 record expressionss copy-and-update, 72 record types automatically implemented interfaces in, 151 members in, 151 scope of field labels, 151 record types, 150 records, 53 recursive definitions, 261, 263 recursive function definition, 112 recursive safety analysis, 264 recursive value definition, 112 reference types zero value of, 119 ReferenceEquality attribute, 189 reflected forms, 233 ReflectedDefinition attribute, 115 reflection, 312 RequireQualifiedAccess attribute, 236 RequiresExplicitTypeArguments attribute, 209 RequiresQualifiedAccess attribute, 166 reraise expressions, 108 resolution function application, 248 method application, 249 script files, 224 Sealed attribute, 151 SealedAttribute attribute, 54 sequence expression, 90 sequence iteration expression, 106 sequential conditional expressions, 105
sequential execution expressions, 104, 124 shortcut and expression, 105 shortcut or expression, 105 signature elements, 217 signature files, 215 anonymous, 224 compilation order of, 222 contents of, 223 signatures conformance of, 218 declarations of, 216 member, 217 module, 206 of namespace declaration groups, 205 type definition, 217 value, 217 slice expressions, 100 source code files, 23 sprintf function, 93 stack allocation, 312 static coercion expressions, 113 static initializer execution of, 226 static initializers, 158 static members, 170 static types, 44 strings, 28 format, 93 newlines in, 29 triple-quoted, 29 strongly typed quoted expressions, 115 struct types default constructor in, 164 struct/end tokens, 163 structs, 53 structural equality, 188 structural types, 189 StructuralComparison attribute, 190 StructuralEquality attribute, 189 symbolic operators, 30, 40 syntactic types, 44 System.Object, 75 System.Reflection objects, 233 System.Tuple, 69 System.Type objects, 233 text formatting, 312 ThreadStatic attribute, 110, 208 tokens hidden, 33, 278 try-finally expressions, 108 evaluation of, 125 try-with expressions, 108, 125 tuple type, 46 type fresh, 45 meanings of, 43 named, 45 statically resolved variable, 46 type abbreviations, 53, 149 type annotations over-constrained, 260 type applications lexical analysis of, 287 type definition group, 145 type definition signatures, 217 type definitions, 43, 53 abstract members in, 183 checking of, 146 delegate, 166 enum, 165 exception, 166 generic, 53 grammar of, 141 interface, 162 interfaces in, 186 kinds of, 144 location of, 144 reference, 54 sealed, 54 struct, 163 type extensions, 167 type functions, 207 signature conformance for, 220 type inference, 13, 45 type inference environment, 45 type kind inference, 148 type parameter definitions, 52 type providers, 19 type variable definition site, 55 type variables, 43 name resolution for, 243 rigid, 55 type-annotated expressions, 113 type-annotated patterns, 136 typedefof operator, 233 type-directed conversions, 178 typeof operator, 233 types anonymous variable. See anonymous variable type array. See array type
base, 55 class, 53, 155 coercion of, 56 comparison of, 188 condensation of generalized function types, 269 constrained, 47 conversion of, 178 delegate, 96, 166 dynamic conversion of, 58 enum, 165 equivalence of, 56 exn (exception), 166 flexible, 150 implicit static members of, 259 initial, 66 interface types of. See interface types logical properties of, 53 name resolution for, 242 nativeptr, 306 partial static, 55 record, 150 reference, 54 renaming, 149 runtime, 43 static, 43 structural, 189 syntactic, 43 tuple. See tuple type union, 152 unit, 107 unmanaged, 51 value, 54 variable, 45 zero value of, 119 undentation, 283, 285 union cases, 121 union types, 152 automatically implemented interfaces for, 153 compiled, 154 members in, 153 unions, 53 unit type, 57, 107 units of measure. See measures unmanaged constraint, 51 val specification, 161 value definition expressions, 109 value definitions, 157, 261 in modules, 207 static, 158 value references, 120 value signatures, 217 value types zero value of, 119 values arity conformance for, 218 processing of definitions, 262 runtime, 117 signature conformance for, 218 verbatim strings, 29 virtual methods, 184 VolatileField attribute, 118 weakly typed quoted expression, 116 while loops, 123 while-loop expression, 107 whitespace, 25 significance in lightweight syntax, 277 with/end tokens, 151, 153 XML documentation tokens, 25 zero value, 119