F# 编译器错误 FS0030,值限制问题
我已阅读 StrangeLights 上的简介,我已阅读以下文章专家 F#(第 119 页),但我看不出它们如何应用于我的代码:
对于我的测试,我想检查浮点数之间的相等性,并具有一定的容忍度。 我正在将所有内容转换为度量单位,但我希望能够成为“通用”:
let toleq (e:float<_>) a b = (abs ( a - b ) ) < e
然后我可以使用它来检查不同“类型”浮点数的相等性,或者将其柯里化以制作自定义浮点:
toleqm = toleq 1.0e-10<m>
但我得到以下消息:
Type inference has inferred the signature
val toleq : float<'u> -> float<'u> -> float<'u> -> bool
Either define 'toleq' as a simple data term, make it a function, or add a
type constraint to instantiate the type parameters.
我不知道如何才能使其成为一个函数 - 我看不到任何隐式参数。
这是怎么回事?
I've read the blurb at StrangeLights, I've read the passage from Expert F# (page 119), but I can't see how they apply to my code:
For my tests, I want to check equality between floats, with a bit of tolerance. I'm converting everything to units of measure, but I want to be able to be 'generic':
let toleq (e:float<_>) a b = (abs ( a - b ) ) < e
I can then use this to check equality on different 'types' of float, or curry it to make a custom one:
toleqm = toleq 1.0e-10<m>
But I get the following message:
Type inference has inferred the signature
val toleq : float<'u> -> float<'u> -> float<'u> -> bool
Either define 'toleq' as a simple data term, make it a function, or add a
type constraint to instantiate the type parameters.
I don't see how I can do any more to make it a function - I can't see any implicit parameters.
What's up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我搞乱了一点,在绝望中找到了解决方案,但我不确定我是否理解为什么......
呃,它几乎和 C# 中的泛型声明一样丑陋。
Well, I messed around a bit and found the solution, in desperation, but I'm not sure that I understand why...
Ugh, it's almost as ugly as generic declarations in C#.