Sunday, 15 April 2012

.net - What/where is get_Zero in F#'s int? -


I'm just learning F #, and I've seen playing that if I change this code:

  [0..100] | & Gt; List. Sum   

to

  ["A"; "B"; "D"] | & Gt; I get the following error:  
  Type 'string' operator does not support 'get_Zero'   

(However, it only works for me in IE!)

When I checked; It says that this type should have a stable member called Zero. It seems to explain the error; Apart from the fact that I can not see any member who is Zero On Int!

Therefore; Where is it zero member which applies to ints? I can not see it in intellisense if I int , and neither, who says that int is just a .NET system Input 32 (which is a static zero property).

(Note: It says "operator" and does not "member" in error, which may be related; although List.sum definition only states "member").

F = source code is using diggers,
  inline amount (source: cac & lt; (^ a) ) & Gt;): ^ A = Usage e = source.GetEnumerator () Exchanges acc = LanguagePrimitives.GenericZero & lt; (^ A) & gt; On the other hand, the F # compiler creates a table to see the zero values ​​of all the built-in arts, while E. Before asking zero members, there is a code piece in the numerical type in the related bits and below.  
  type GenericZeroDynamicImplTable & lt; 'T & gt; () = Turn Static Results: 'T = // Dynamic Implementation AT = Typef < 'T & gt; If AT Eccles (typef  gt; unboxPrim & lt; 'T & gt; (Box 0y) Alif AT Ecklace (typef & lieutm; int16 & gt;) unboxPrim & lt; 'T & gt; (Box 0s) alif AT Ecloss (typewriter; int 32 & gt;) unboxPrim & lt; 'T & gt; (Box 0) Alif AT The aquals (typef ) then unboxPrim & lt; 'T & gt; (Box 0u) Alif AT Eccles (typef ) then unboxPrim & lt; 'T & gt; (Box 0UL) Alif AT The aquals (typewf; lieutenant; eu lint & gt;) then unboxPrim & lt; 'T & gt; (Box 0un) alif AT Ecloss (typewf; Lieutenius; decim & gt;) unboxPrim & lt; 'T & gt; (Box 0m) alif AT Aquales (typef.lt; float & gt;) then unboxPrim & lt; 'T & gt; (Box 0.0) Alif AT Ecklace (typef> lie 32 & gt;) unboxPrim & lt; 'T & gt; (Box 0.0f) and let's pinpoint = AT GetProperty ("Zero") unboxPrim & lt; 'T & gt; (Pinfo.GetValue (empty, zero)) Stable member results: 't = result   

that said, if you use List.sum on the user Want - Defined type, you obviously need to define zero members. Note that in the case of string type zero does not matter much.

No comments:

Post a Comment