runghc 非常慢(打印数组需要 17-33 秒)

runghc very slow (17-33 Seconds just for Printing an Array)

在我的大学,我目前有一个关于 Haskell 的讲座。现在我得到了一份制作程序的工作。我们得到了这个示例文件: https://pastebin.com/6wPdEgHZ

从那开始,我们必须围绕它开发程序。函数模拟数据库访问。

因为我不喜欢在 WinHugs 中编程,所以我使用 GHC 设置了 Visual Studio 代码。我添加了一个 main-Function 来打印出 Function-Outputs。它看起来像这样:

module Main where

main :: IO ()
main = print artikel

我将其添加到顶部。而已。起初我想输出文章。那是 runghc 输出:

[Running] runghc "c:\UsersCG949285X\Documents\DHBW_Semester\Funktionale Programmierung\restaurant.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 24.527 seconds

[Running] runghc "c:\UsersCG949285X\Documents\DHBW_Semester\Funktionale Programmierung\restaurant.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 30.182 seconds

如您所见,这需要很长时间。仅仅是因为文件中有很多代码吗?还是我设置有误?

如果我让文件保持原样,只需将 module Restaurant where 放在顶部并在同一目录中添加第二个名为“Main.hs”的文件,如下所示:

module Main where

import Restaurant

main :: IO ()
main = print artikel

它运行快多了。

如果我 运行 那 Main.hs 它看起来像这样:

[Running] runghc "c:\UsersCG949285X\Documents\DHBW_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.473 seconds

[Running] runghc "c:\UsersCG949285X\Documents\DHBW_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.434 seconds

[Running] runghc "c:\UsersCG949285X\Documents\DHBW_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.487 seconds

如此之快,而且实际上可以使用。最后,要求是只提供一个在 WinHugs 中工作的单个 .hs 文件。所以我想我现在会继续在我的 Main.hs 中工作,并在我完成后将其合并回原始文件。应该可以。

感谢@all