2

我似乎无法在haskell上获得光泽。我已经通过“cabal install gloss”安装了gloss-1.8.0.1。这是我的 circle.hs 文件。

import Graphics.Gloss
main = display (InWindow "Nice Window" (200, 200) (10, 10)) white (Circle 80)

据我了解,当我通过 ghci 打开这个文件时。将弹出一个名为“Nice Window”的窗口,它会为我很好地画出我的圆圈。

但是,当我打开它时。这是输出。

[1 of 1] Compiling Main             C:\Users\... Path here, interpreted
Ok, modules loaded: Main.
*Main>

即使我尝试直接在 ghci 中绘制

import Graphics.Gloss
picture = circle 80

会回来

<interactive>:3:9 parse error on input '='
4

2 回答 2

6

您已经定义了 a main,但没有告诉 ghci 您想要执行它。为此,只需键入main. 如果您的程序需要参数,您可以使用:main arg1 arg2来传递arg1arg2就好像它们在命令行上一样。

在 ghci 中定义事物时,必须使用let. 所以要定义picture,你会写

let picture = circle 80

和前面的一样,这定义picture了它,但不做任何事情;如果你想让某事发生,你必须确切地说出要执行的代码。

于 2013-10-17T21:47:37.403 回答
2

使用runhaskell而不是ghci.

于 2013-10-18T00:49:34.630 回答