Haskell leksah 你好世界

发布于 2024-10-11 22:14:13 字数 673 浏览 9 评论 0原文

今天早上有坏消息,我愿意尝试使用 Leksah(顺便说一下,看起来不错的应用程序)来继续学习 haskell。

我无法编译在阅读leksah 教程时发现的“Hello World”示例。

module Main (
main = putStrLn "Hello World"     
) where

编译错误:src\Main.hs:16:5:输入解析错误='`

module Main (
) where
main = putStrLn "Hello World"

编译错误:src\Main.hs:1:0:主函数< /code>main' 未由模块 Main' 导出

您建议我尝试其他方法吗?

重要编辑现在 Leksah 附带了一个文件 Main.hs,在您第一次启动 leksah 时直接加载,其中包含一个功能齐全的 Hello World 迷你项目。它还具有极简的单元测试对应部分。非常适合初学者:-)

bad news this morning, I was willing to try and use Leksah (nice looking application by the way) for continuing learning haskell.

I couldnt compile the "Hello World" example I found reading the leksah tutorial.

module Main (
main = putStrLn "Hello World"     
) where

compilation-error: src\Main.hs:16:5: parse error on input='`

and

module Main (
) where
main = putStrLn "Hello World"

compilation-error: src\Main.hs:1:0: The main functionmain' is not exported by module Main'

What would you advise me to try something else ?

IMPORTANT EDIT: Now Leksah is shipped with a file Main.hs, loaded directly the first time you launch leksah, that contains a fully functionnal Hello World mini project. It has also minimalist unit test counter part. Great for beginners :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

韵柒 2024-10-18 22:14:13

模块名称后面括号中的文本是导出列表。这意味着,您必须将要导出的程序中的所有函数都放入其中。但除此之外,您还必须在某处定义您的主要功能。试试这个:

module Main (
  main
) where
main = putStrLn "Hello World"

PS:您还可以删除括号和其中的任何内容,而不是模块中的任何内容都将被导出。

The text in the paranthesis after the module name is an export list. This means, that you have to put all functions in the program you want to export in there. But apart from this, you also have to define your main function somewhere. Try this:

module Main (
  main
) where
main = putStrLn "Hello World"

PS: You can also remove the paranthesis and anything in there, than anything in your module is going to be exported.

苏辞 2024-10-18 22:14:13

您的第二个示例即将完成,只需从 Main 旁边删除 () 即可。这是您的模块的导出列表,您已将其清空(括号内没有任何内容)。因此,看不到 main (因为它没有导出)。

您也可以只导出 main:

module Main (main) where

Your second example is almost there, just remove the () from beside Main. This is your export list for your module, which you have made empty (nothing in-between the parentheses). Because of that, main isn't seen (because it's not exported).

You could also just export main:

module Main (main) where
记忆で 2024-10-18 22:14:13

“出口所有东西是个好习惯吗?”绝对不是。您不希望像辅助方法这样的实现细节泄漏到外部。另一个例子是值构造函数,因为无法对它们进行健全性检查、默认参数等。为了克服这个问题,您只能在模块内部使用它们,并为外部提供方便且安全的初始化函数。

"Is it good practice to export everything?" Definitely not. You don't want that implementation details like helper methods leak to the outside. Another example are value constructors, because there is no way to have sanity checks, default arguments etc for them. To overcome this, you use them only inside the module, and provide convenient and safe initialization functions for the outside.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文