通过打开Checked
模块,F#允许使用已检查的算术,该模块重新定义了要检查的标准运算符,例如:
open Checked
let x = 1 + System.Int32.MaxValue // overflow
将导致算术溢出异常。
但是,如果我想在小范围内使用校验算法,比如C#允许使用关键字checked
怎么办
int x = 1 + int.MaxValue; // ok
int y = checked { 1 + int.MaxValue }; // overflow
如何通过打开Checked
模块来控制运算符重新定义的范围,或者使其尽可能小?
https://stackoverflow.com/questions/2271198
复制相似问题