Iceandele
Iceandele

Reputation: 660

Getting Gloss to work in Haskell

I can't seem to get gloss working on haskell. I already have gloss-1.8.0.1 installed via "cabal install gloss". This is my circle.hs file.

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

From my understanding, when I open this file via ghci. A window will pop up with the name "Nice Window" and it will have my circle nicely drawn out for me.

However, when I open it. here's the output.

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

Even when I try to draw directly in ghci

import Graphics.Gloss
picture = circle 80

would return

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

Upvotes: 2

Views: 1562

Answers (2)

alternative
alternative

Reputation: 13002

Use runhaskell instead of ghci.

Upvotes: 2

Daniel Wagner
Daniel Wagner

Reputation: 152707

You've defined a main, but didn't tell ghci that you wanted to execute it. To do that, simply type main. In case your program needs arguments, you can use :main arg1 arg2 to pass arg1 and arg2 as if they were on the command-line.

When defining things inside ghci, you must use let. So to define picture, you would write

let picture = circle 80

As with the previous thing, this defines picture but doesn't do anything with it; if you want something to happen, you'll have to say exactly what code to execute.

Upvotes: 6

Related Questions