有了这个代码:
main :: FilePath -> FilePath -> IO ()
main wrPath rdPath = do x <- readFile rdPath
writeFile wrPath x
我收到以下错误:
Couldn't match expected type 'IO t0'
with actual type 'FilePath -> FilePath -> IO()
但是当我将“main”的名称更改为其他名称时,该文件可以正确编译。
main 有什么独特之处以及为什么它的类型必须是IO t0
?
因为语言规范says so.
Haskell 程序是模块的集合,按照惯例,必须调用其中一个模块Main
并且必须导出该值main
。程序的值就是标识符的值main
在模块中Main
,它必须是类型的计算IO t
对于某些类型t
(见第 7 章)。当程序执行时,计算main
被执行,其结果(类型t
)被丢弃。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)