所以我通过一些样品的F#代码的工作,跑到下面的代码片段:类型约束不匹配默认INT *整型师
let divRem a b =
let x = a/b
let y = a % b
(x,y)
当我尝试编译它,我得到以下错误:
HelloWorld\Program.fs(15,14): error FS0071: Type constraint mismatch when applying the default type 'int * int' for a type inference variable. The type '(int * int)' does not support any operators named '/' Consider adding further type constraints
但是,做这样的事情
let print n = System.Console.WriteLine(n.ToString())
print (4/2)
结果
2
为什么整数除法操作在函数定义中不可用?
编辑: 下面是整个代码未能编译的示例。
let divRem a b =
let x = a/b
let y = a % b
(x,y)
let print n = System.Console.WriteLine(n.ToString())
print (divRem (5,3))
由行号猜测时使用该功能的实际误差。请发布您的整个F#文件,但无法编译 – 2012-02-09 05:18:13