作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Possible Duplicate:
Return specific type within Haskell
这段代码:
class Alpha a where
half :: Real f => a -> f
instance Alpha Double where
half a = a/2.0
产生此错误:
rigid.hs:6:13:
Couldn't match expected type `f' against inferred type `Double'
`f' is a rigid type variable bound by
the type signature for `half' at rigid.hs:3:17
In the expression: a / 2.0
In the definition of `half': half a = a / 2.0
In the instance declaration for `Alpha Double'
Failed, modules loaded: none.
为什么?
编辑:弄清楚刚性类型的业务,我想我已经找到了一个更有针对性的问题。如何将 Double 转换为满足 Ord 和 Num 的值?也就是说,一个让我得到 (Ord a, Num a) => Double -> a
的函数?
最佳答案
您声称 half
可以将类型 a
转换为任何 Real
类型。但你的 half
只能将 a
(Double
) 转换为 Double
。
关于Haskell 刚性类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3183984/
这是 opencv: Rigid Transformation between two 3D point clouds 的重复问题.但是,没有接受任何答案,我不明白那里唯一的答案。 唯一的答案是缩放和
我需要一个 ODE 求解器来解决类似于 MATLAB ode15s 的刚性问题。 对于我的问题,我需要检查不同初始值需要多少步(计算)并将其与我自己的 ODE 求解器进行比较。 我试过用 solver
我是一名优秀的程序员,十分优秀!