0

i want to try out the threepenny-gui package for haskell. So i run

cabal install threepenny-gui

... without any problems

So i tried the following example:

module Main where

import qualified Graphics.UI.Threepenny as UI
import                  Graphics.UI.Threepenny.Core

main :: IO ()
main = do
    startGUI defaultConfig setup

setup :: Window -> IO ()
setup window = do
    return window # set UI.title "Hello World!" 

    button <- UI.button # set UI.text "Click me!"
    getBody window #+ [element button]

    on UI.click button $ const $ do
        element button # set UI.text "I have been clicked!"

but i get a Errors about the types:

threePennyHelloWorld.hs:8:28:
    Couldn't match type `IO ()' with `UI ()'
    Expected type: Window -> UI ()
      Actual type: Window -> IO ()
    In the second argument of `startGUI', namely `setup'
    In a stmt of a 'do' block: startGUI defaultConfig setup

threePennyHelloWorld.hs:12:25:
    Couldn't match type `UI Window' with `IO a0'
    Expected type: UI Window -> IO a0
      Actual type: UI Window -> UI Window
    In the second argument of `(#)', namely `set title "Hello World!"'
    In a stmt of a 'do' block: return window # set title "Hello World!"

threePennyHelloWorld.hs:14:31:
    Couldn't match type `UI Element' with `IO Element'
    Expected type: UI Element -> IO Element
      Actual type: UI Element -> UI Element
    In the second argument of `(#)', namely `set text "Click me!"'
    In a stmt of a 'do' block:
      button <- UI.button # set text "Click me!"

threePennyHelloWorld.hs:15:9:
    Couldn't match type `UI' with `IO'
    Expected type: IO Element
      Actual type: UI Element
    In a stmt of a 'do' block: getBody window #+ [element button]
    In the expression:
      do { return window # set title "Hello World!";
           button <- UI.button # set text "Click me!";
           getBody window #+ [element button];
           on UI.click button
           $ const $ do { element button # set text "I have been clicked!" } }
    In an equation for `setup':
        setup window
          = do { return window # set title "Hello World!";
                 button <- UI.button # set text "Click me!";
                 getBody window #+ [element button];
                 .... }

threePennyHelloWorld.hs:17:9:
    Couldn't match type `UI' with `IO'
    Expected type: IO ()
      Actual type: UI ()
    In a stmt of a 'do' block:
      on UI.click button
      $ const $ do { element button # set text "I have been clicked!" }
    In the expression:
      do { return window # set title "Hello World!";
           button <- UI.button # set text "Click me!";
           getBody window #+ [element button];
           on UI.click button
           $ const $ do { element button # set text "I have been clicked!" } }
    In an equation for `setup':
        setup window
          = do { return window # set title "Hello World!";
                 button <- UI.button # set text "Click me!";
                 getBody window #+ [element button];
                 .... }

even when i try to run an example File, i get the same errors

Does anyone have an idea what i'am doing wrong?

Xlaech
  • 456
  • 3
  • 19

1 Answers1

8

setup is in the UI monad, not IO, so change the type declaration:

setup :: Window -> UI()

As for example in https://github.com/HeinrichApfelmus/threepenny-gui/blob/master/samples/BarTab.hs

JP Moresmau
  • 7,388
  • 17
  • 31
  • thanks a lot... i feel kind of stupid now. I should have seen that, but since i wrote it after a tutorial i was a little bit confused. – Xlaech Apr 10 '15 at 21:28