
Code here: http://zem.novylen.net/anagrid.html I've got an instance of IO appearing unexpectedly and I can't figure out where from. It throws up the following error: $ ghc --make test.hs Chasing modules from: test.hs Compiling Main ( test.hs, test.o ) test.hs:38:15: Couldn't match `StaticText ()' against `IO (StaticText ())' Expected type: StaticText () Inferred type: IO (StaticText ()) In the application `staticText p [text := (labelText a b)]' In the definition of `textOf': textOf p a b = staticText p [text := (labelText a b)] martin

Martin DeMello wrote:
Code here: http://zem.novylen.net/anagrid.html
I've got an instance of IO appearing unexpectedly and I can't figure out where from. It throws up the following error:
$ ghc --make test.hs Chasing modules from: test.hs Compiling Main ( test.hs, test.o )
test.hs:38:15: Couldn't match `StaticText ()' against `IO (StaticText ())' Expected type: StaticText () Inferred type: IO (StaticText ()) In the application `staticText p [text := (labelText a b)]' In the definition of `textOf': textOf p a b = staticText p [text := (labelText a b)]
According to the http://wxhaskell.sourceforge.net/doc/Graphics.UI.WX.Controls.html page, "staticText" has the type signature "Window a -> [Prop (StaticText ())] -> IO (StaticText ())". Your textOf function has the type signature "Panel () -> String -> Anagrams -> StaticText ()". Your textOf *definition*, therefore, something of type "StaticText()" left side and type "IO (StaticText ())" on the right. The compiler doesn't like that.

On 2/8/07, Martin DeMello
Code here: http://zem.novylen.net/anagrid.html
I've got an instance of IO appearing unexpectedly and I can't figure out where from. It throws up the following error:
$ ghc --make test.hs Chasing modules from: test.hs Compiling Main ( test.hs, test.o )
test.hs:38:15: Couldn't match `StaticText ()' against `IO (StaticText ())' Expected type: StaticText () Inferred type: IO (StaticText ()) In the application `staticText p [text := (labelText a b)]' In the definition of `textOf': textOf p a b = staticText p [text := (labelText a b)]
Hi, Martin-- I didn't know what staticText did, so I looked it up in the wxHaskell documentation (http://wxhaskell.sourceforge.net/doc/index.html, for anyone who might be following along at home.) As it turns out, staticText returns an IO action that returns a StaticText(), so that explains your error: the type signature you gave for textOf says that it returns something in the StaticText monad, but the body of textOf consists of a call to staticText, which returns something in the IO monad. So textOf also has to have an IO type for its return type. (Intuitively, that's because creating the GUI object that represents the label is a side-effecting operation, at least with the way wxHaskell is designed.) Cheers, Kirsten -- Kirsten Chevalier* chevalier@alum.wellesley.edu *Often in error, never in doubt "make them believe, if not in magic, in money well spent" -- Annie Gallup
participants (3)
-
Kirsten Chevalier
-
Martin DeMello
-
Seth Gordon