开发者

F# NumericLiteral: FromString method

开发者 https://www.devze.com 2023-01-01 07:05 出处:网络
Does anyone know if there is a way to automatically invoke the FromString method of a numeric literal in F#? I have already tried (and succeeded) with the methods FromOne, FromZero, etc but I have no

Does anyone know if there is a way to automatically invoke the FromString method of a numeric literal in F#? I have already tried (and succeeded) with the methods FromOne, FromZero, etc but I have no idea how开发者_高级运维 strings could be handled at compile time...


from page 51 of the F# language specification:

xxxx<suffix>
For xxxx = 0 -> NumericLiteral<suffix>.FromZero()
For xxxx = 1 -> NumericLiteral<suffix>.FromOne()
For xxxx in the Int32 range -> NumericLiteral<suffix>.FromInt32(xxxx)
For xxxx in the Int64 range -> NumericLiteral<suffix>.FromInt64(xxxx)
For other numbers -> NumericLiteral<suffix>.FromString("xxxx")

That means, only when the first 4 are not satisfied, FromString is called. Also, xxxx must be digits with signs, you cannot use other alphabeta set for xxxx.


I think it's intended for numbers bigger than Int64.MaxValue.

0

精彩评论

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