【发布时间】:2013-04-05 12:02:10
【问题描述】:
以下 Haskell 代码段无法编译,我不知道为什么。
runCompiler :: TC -> IO ()
runCompiler tc = let cp' = cp in
do
cp'
return ()
where
cp = compileProg tc
我从 GHCi 收到以下错误:
Couldn't match expected type `IO a0' with actual type `String'
In a stmt of a 'do' block: cp'
In the expression:
do { cp';
return () }
In the expression:
let cp' = cp
in
do { cp';
return () }
任何想法如何使它编译。我不明白为什么它不接受 () 作为给定的最终值。
【问题讨论】:
-
compileProg 的类型签名是什么?
-
为什么要将
compileProg tc绑定到cp'和cp?为什么在同一个函数中同时使用let和where?令人困惑。 -
当我将其更改为下面的答案时,它会编译。现在我的问题是让它输出 compileProg 返回的字符串。