[Haskell-cafe] still wrestling with io

Kirsten Chevalier catamorphism at gmail.com
Thu Feb 8 11:51:14 EST 2007


On 2/8/07, Martin DeMello <martindemello at gmail.com> 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)]

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 at alum.wellesley.edu *Often in error, never in doubt
"make them believe, if not in magic, in money well spent" -- Annie Gallup


More information about the Haskell-Cafe mailing list