[Haskell-beginners] Pb with toggleActionNew

Nick Vanderweit nick.vanderweit at gmail.com
Sun Jul 22 23:13:30 CEST 2012

Besides the fact that you are trying to pass the result of toggleActionNew as 
an argument, you're going to end up with problems regarding the type signature 
of togls when you try to invoke toggleActionNew, whose type signature is:

toggleActionNew :: String
                -> String
                -> Maybe String 
                -> Maybe String 
                -> IO ToggleAction

So it's a function that, when passed its four arguments, yields an IO 
ToggleAction. One of the important aspects of the IO monad is that it can't be 
(safely) escaped, so unlike many monads, there isn't a function:

escapeIO :: IO a -> a *

This is how the type system enforces that your Int -> Int functions can't 
write to the hard drive, or accept input from stdin, for instance. The only 
way to capture the result of an (IO a) is to use >>= and get another (IO b). 
This means that your type signature for togls is impossible, and it appears 
you should instead try for:

togls :: IO [ToggleAction]

In short: rethink what the possible types are, and don't misinterpret the 
result of a function as one of its arguments.

- Nick

* Actually, this function does exist. It is called unsafePerformIO in 
System.IO.Unsafe, and you really shouldn't use it unless you know what you are 

On Sunday, July 22, 2012 04:46:56 PM Pierre Michallet wrote:
> I am trying to become acquainted with both haskell and Gtk thru the writing
> of small pieces of code exercising some Gtk functions. Having had problems
> with the ToggleEntry function (unable to get the checked/non checked status
> - refer to chapter 7.2 of the Gtk2HS tutorial) I have tried to understand
> the toggleAction thing.
> So I have written this :

> import  Graphics.UI.Gtk.ActionMenuToolbar.ToggleAction
> ...
> togls::[ToggleAction]
> togls = let stone = toggleActionNew "STON" "Stones number" Nothing  Nothing 
> (myTog stone) deste = toggleActionNew "DEST" "Destination" Nothing Nothing 
> (myTog deste) state = toggleActionNew "STAT" "Board status" Nothing Nothing
>  (myTog state) in [stone,deste,state]
> myTog::ToggleAction->IO()
> myTog ta =  putStrLn ("The name of the action is " ++ (toggleActionName ta))
> The compiler is not happy with this and sends back the following:
> ----------------------------------------------------------------------------
> ---------------------------------------------------------------
> The function 'toggleActionNew' is applied to five arguments but its type
> 'String ->String ->Maybe String -> Maybe stockId ->IO ToggleAction has only
> four.
> ----------------------------------------------------------------------------
> --------------------------------------------------------------- To me, stone
> has 4 parameters ("STON", "Stones number", Nothing,Nothing) and a result
> (myTog stone) as in the definition given by the compiler. I am using
> ghc-7.0.3
>                 gthk+-bundle_2.16.2-20090601_win32
>                 gtk- documentation
> I am certainly missing something obvious to everybody but I could not solve
> it , so I would appreciate any help on this topic.
> Thanks in advance
> p.michallet at free.fr

More information about the Beginners mailing list