gpt4 book ai didi

haskell - Haskell 或 GHC 的主要定义在哪里?

转载 作者:行者123 更新时间:2023-12-05 01:04:24 25 4
gpt4 key购买 nike

在 Haskell 中,编译程序的执行从在模块 Main 中执行 main 开始。此函数必须是 IO () 类型。

哪个标准或引用定义了上述内容?

Haskell 2010Haskell 98不要正式定义main(虽然有几个函数的例子叫做main),而是说:

We leave as implementation dependent the ways in which Haskell programs are to be manipulated, interpreted, compiled, etc.

GHC User's Guide指示用户创建一个 main 函数,但从未提及其所需类型或它是程序执行的开始。有对 Main 模块的引用,但没有 main 函数。

比较 C++ (引用 C11 标准 (ISO/IEC 9899:2011) 5.1.2.2.1 程序启动 (p: 13)):

Every C program [...] contains the definition [...] of a function called main, which is the designated start of the program.

哪个标准或引用说 main 是 Haskell 程序执行的开始?

最佳答案

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 τ for some type τ (see Chapter 7). When the program is executed, the computation main is performed, and its result (of type τ) is discarded.

https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#dx11-98001

关于haskell - Haskell 或 GHC 的主要定义在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72067550/

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