haskell - Haskell错误消息需要另外一个参数

标签 haskell compiler-errors

我试图解决这种等式:当已知d时,e ^ x + sqrt(x)= d。它没有解析解决方案,因此我使用二进制搜索的变体来解决它:

helper x = exp x + sqrt x

ex2 c0 c1 x 
| abs (h0 - h1) < 10 ^^ (-6) = c0
| hm < x = ex2 m c1 x
| hm >= x = ex2 c0 m x
where h0 = helper c0
  h1 = helper c1
  m = c0 + (c1 - c0)/2
  hm = helper m

这从ghci可以正常工作(c0和c1是搜索的最小值和最大值),但是我在从stdio读取参数x时遇到问题:
main = do
 seed <- getLine
 let output = show ex2 0 6 (read seed :: Floating) -- Result is somewhere between helper(0) and helper(6)
     in putStrLn output

这破坏了我的代码。它不会在ghci中编译或加载。我收到此错误消息:

ex2.hs:14:46:
期待有更多关于“ float ”的论点
预期为一种类型,但“ float ”类型为“*->约束”
在表达式类型签名中: float
在“显示”的第四个参数中,即“((read seed::Floating)”
在表达式中:show ex2 0 6(读取种子:: float )

有人可以解释一下这是什么意思以及如何修复我的主要功能吗?

最佳答案

let ..行中缺少括号:

另一个错误:show(ex2 ...(read seed::Double))需要括号。 – chi

关于haskell - Haskell错误消息需要另外一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27970545/

相关文章:

haskell - 如何使用自定义App类型代替IO?

haskell - 函数在类型级别上的模式匹配是可能的,但在值级别上则不行,为什么会出现这种差异?

haskell - monad 中的纯映射

haskell - 我如何在 Haskell 中显示派生树?

.net - 基本 CLI 库 'mscorlib' 与引用的 F# 核心库二进制不兼容

compiler-errors - Typescript 中的解构导致编译器错误 TS1008 和 TS1005

java - Netbeans如何恢复编译错误弹出

haskell - stack 如何从 extra-deps 中找到包?

compiler-errors - 部署IBM Mobile v8.0.0 MobileFirst HTTP Adater错误- “Adapter deployment failed: A database error was detected.”

eclipse - 为什么我在Eclipse中收到此错误-可能是Java运行时版本不兼容吗?