开发者

Questions about the definition of lazy

开发者 https://www.devze.com 2022-12-17 06:07 出处:网络
On line 5633 in prim-types.fs (v1.9.7.8) there is the following type abbreviation: type \'T ``lazy`` = Lazy<\'T>

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.

  1. What do the double backticks mea开发者_JS百科n?
  2. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号