let ident1 : ty1 = expr1 try expr2 finally (match (ident :> obj) with | null -> () | _ -> (ident :> System.IDisposable).Dispose()) Type-Related Expressions Type-Annotated Expressions A type-annotated expression has the following form, where ty indicates the static type of expr: expr : ty For example: (1 : int) let f x = (x : string) + x When checked, the initial type of the overall expression is asserted to be equal to ty. Expression expr is then checked with initial type ty. The expression elaborates to the elaborated form of expr. This ensures that information from the annotation is used during the analysis of expr itself. Static Coercion Expressions A static coercion expression—also called a flexible type constraint—has the following form: expr :> ty The expression upcast expr is equivalent to expr :> _, so the target type is the same as the initial type of the overall expression. For example: (1 :> obj) ("Hello" :> obj) ([1;2;3] :> seq<int>).GetEnumerator() (upcast 1 : obj) The initial type of the overall expression is ty. Expression expr is checked using a fresh initial type tye, with constraint tye :> ty. Static coercions are a primitive elaborated form. Dynamic Type-Test Expressions A dynamic type-test expression has the following form: expr :? ty For example: ((1 :> obj) :? int) ((1 :> obj) :? string) The initial type of the overall expression is bool. Expression expr is checked using a fresh initial type tye. After checking:
let ident1 : ty1 = expr1 try expr2 finally (match (ident :> obj) with | null -> () | _ -> (ident :> System.IDisposable).Dispose()) Type-Related Expressions Type-Annotated Expressions A type-annotated expression has the following form, where ty indicates the static type of expr: expr : ty For example: (1 : int) let f x = (x : string) + x When checked, the initial type of the overall expression is asserted to be equal to ty. Expression expr is then checked with initial type ty. The expression elaborates to the elaborated form of expr. This ensures that information from the annotation is used during the analysis of expr itself. Static Coercion Expressions A static coercion expression—also called a flexible type constraint—has the following form: expr :> ty The expression upcast expr is equivalent to expr :> _, so the target type is the same as the initial type of the overall expression. For example: (1 :> obj) ("Hello" :> obj) ([1;2;3] :> seq<int>).GetEnumerator() (upcast 1 : obj) The initial type of the overall expression is ty. Expression expr is checked using a fresh initial type tye, with constraint tye :> ty. Static coercions are a primitive elaborated form. Dynamic Type-Test Expressions A dynamic type-test expression has the following form: expr :? ty For example: ((1 :> obj) :? int) ((1 :> obj) :? string) The initial type of the overall expression is bool. Expression expr is checked using a fresh initial type tye. After checking:
FSharpSpec-4.1-latest.docx