Questions about the definition of lazy
On line 5633 in prim-types.fs (v1.9.7.8) there is the following type abbreviation:
type 'T ``lazy`` = Lazy<'T>
I have a few questions about it.
- What do the double backticks mea开发者_JS百科n?
- Is this definition equivalent to
type lazy<'T> = Lazy<'T>
? (If not, how is it different?)
The double back ticks are a way of allowing an F# keyword to be used as an identifier. Another example would be
let ``let`` = 42
To answer the second half of your question, generic types in F# can be specified using either the O'Caml-style syntax where the generic parameter precedes the type (e.g 'a list
, int array
, etc.), or the .NET-style with angle brackets (e.g. list<'a>
, array<int>
, etc.), so the two definitions are indeed basically equivalent (except that your version as written is syntactically invalid because lazy
is a keyword). For multi-parameter generic types, the O'Caml style is deprecated and will generate a warning (e.g. let (m:(int,string) Map) = Map.empty
should be rewritten as let (m:Map<int,string>) = Map.empty
).
精彩评论