Share via


How not to name types and identifiers

From the 'code which is valid but looks strange and might be removed in the next release of F#, but isn't a big deal anyways' department: Adding managed, generic .Net names as part of the inference proceedure process.

#light

open System.Collections.Generic

let x = new ``List`1``<int>([1..10])

 

Note that you need to use the double back ticks "``" in order to declare the type name, otherwise you get a syntax error. Back ticks allow you to specify a literal type name, in case it conflicts with an F# keyword. For example, you can create a C# type named 'unit'. This also allows you to write the strange, yet valid code:

 

let ``_`` = 3

let f x = 3 * 3

assert ((f ``_``) = 9)

 

Yes, using back ticks you can name an identifier '_'. Not especially useful, but interesting none the less.