gpt4 book ai didi

Haskell - 是什么让 'main' 独一无二?

转载 作者:行者123 更新时间:2023-12-02 12:20:48 27 4
gpt4 key购买 nike

使用此代码:

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 .

A Haskell program is a collection of modules, one of which, by convention, must be called Main and must export the value main. The value of the program is the value of the identifier main in module Main, which must be a computation of type IO t for some type t (see Chapter 7). When the program is executed, the computation main is performed, and its result (of type t) is discarded.

关于Haskell - 是什么让 'main' 独一无二?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6258609/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com