This sounds as though it may be 'homework', so hints only - your
professor
may well be reading in any case. Please see
http://www.haskell.org/haskellwiki/Homework_help
for more information.

- To make something happen when you press a button, you need to add an
event
  handler to the button.
- One way of doing this in wxHaskell is to reference the event handler
in
  the button attributes when you create it.
- Your event handler needs to be able to identify the text label so that
it
  can update it with new contents.

Almost all functions in wxHaskell run in the IO monad, as you have
observed.
While you cannot 'take away' the IO, you can use values which are
embedded
with an IO type, for example, suppose you have a function (these are
deliberately not quite the same as the 'real' wxHaskell functions, but
should give you an idea):

button :: Window -> [Attribute] -> IO Button
frame  :: Maybe Window -> [Attribute] -> IO Frame

You can create a button in a frame with code something like the
following:

main () =
  do
    f <- frame Nothing [Title "My Frame"]
    b <- button f [Text "Press Me", Event evtHandler]

Notice that 'f' and 'b' give access to the frame and button information.
They
can do this because everything inside the 'do' is already in the IO
monad.

Now, in wxHaskell, the functions you will need to use are a little
different,
but the principles are very similar. In particular, there is a function, 
'set' which may be helpful to you for some of the task.

It is described in more detail at:
http://wxhaskell.sourceforge.net/doc/Graphics-UI-WX-Attributes.html#v%3Aget

I'll be happy to help with more specific questions, but in such case I
think
you should post what you have, and please bear in mind that I'll try to
help
you to find the correct answer yourself.

Regards
Jeremy

On Mon, 30 Nov 2009 16:35 +0100, "Henk-Jan van Tuyl" <hjgt...@chello.nl>
wrote:
> 
> The solution is described in the page:
>    http://www.haskell.org/haskellwiki/How_to_get_rid_of_IO
> 
> You can find answers to many questions on the haskell site by typing  
> keywords in the search field in the upper left corner; however, words of  
> three letters or less are not indexed, so you will need Google for this.  
> Use a search string like:
>    IO site:haskell.org/haskellwiki
> to find pages about IO
> 
> On Fri, 27 Nov 2009 20:08:44 +0100, <mindfield...@yahoo.com> wrote:
> 
> > Hi!
> > I am new to haskell and I would like to do a seemingly very simple task  
> > in it(using wxhaskell).
> > I would like to change properties based on data acquired from the  
> > outside world(i.e real time, typed text etc.). Probably it sounds stupid  
> > but I simpy cannot do this for days. I am very confused and it is  
> > annoying how a simple task as this is so difficult.
> > Here are what I tried to do:
> >
> > Given a text label and a button, Evry time I press the button I'd like  
> > to read a system dependent time data(for example getCPUTtime) and write  
> > it back on the label.
> >
> > Given a text label and a timer. Evry time the timer condition fires i'd  
> > like to read a system dependent time data...(like above) and write it  
> > back
> >
> > I couldn't do any of these. Mostly because if acquire any data it comes  
> > in the form of IO <sometype> and set doesn't accept IO type. So I cannot  
> > set the new value.
> > I coouldn't find any function in the wxhaskell documentation or  
> > tutorials that sets anything based on IO types.
> > I also found a function unsafePerformIO which could convert an IO to a  
> > non IO type but I couldn't do it anyway. I almost did the second task  
> > but the label didn't refresh by itself. It only refreshed itself when I  
> > moved the window along or continually resized it.
> >
> > Can anybody help me? Ther must be some way to do these things. They  
> > cannot be impossible because they are very basic tasks.
> 
> 
> -- 
> Met vriendelijke groet,
> Henk-Jan van Tuyl
> 
> 
> --
> http://Van.Tuyl.eu/
> http://functor.bamikanarie.com
> http://members.chello.nl/hjgtuyl/tourdemonad.html
> --
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day 
> trial. Simplify your report design, integration and deployment - and
> focus on 
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> wxhaskell-users mailing list
> wxhaskell-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wxhaskell-users
-- 
  Jeremy O'Donoghue
  jeremy.odonog...@gmail.com


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to