
Thanks for your reply but it doesn't quite solve the problem. This:
plist <- mapM (\x-> (panel nb [])) my_list
returns [Panel()] and works as you say, but:
elist <- mapM (\x-> (textCtrl (panel nb []) [text := contents x]))
my_list
still won't work because the function panel returns a IO (Panel()) and
so won't do as a parameter to textCtrl.
I can get round this by applying mapM to a list of the indices (of
my_list and plist:
elist <- mapM (\ix-> (textCtrl (plist!!ix) [text := contents (my_list!!
ix)])) [1..4]
but this seems a bit crap. There must be a neat way of doing this.
N
On Jan 7, 4:21 pm, Daniel Fischer
On Friday 07 January 2011 17:09:11, b1g3ar5 wrote:
I've tried to solve this but I am failing.
I can do this:
p0<-panel nb [] e0<-textCtrl p [text:=my_list!!0]
but I want to do this on all of my_list, so I tried:
let es = map (\x-> textCtrl (panel nb []) [text:=x]) my_list
Now, this won't work because the panel nb [] is IO (Panel()) and the parameter to textCtrl needs to be a Panel()
How do I get out of IO?
What you need is mapM:
es <- mapM (\x -> textCtrl (panel nb []) [text:=x]) my_list
mapM :: (Monad m) => (a -> m b) -> [a] -> m [b]
applies the function to each list element, runs the resulting action and collects the results. If you don't need the results but only the effects of running the actions (common in IO), use
mapM_ :: (Monad m) => (a -> m b) -> [a] -> m ()
mapM and mapM_ are compositions of
sequence :: (Monad m) => [m a] -> m [a]
resp.
sequence_ :: (Monad m) => [m a] -> m ()
with map (mapM f list === sequence (map f list)), those are useful on their own too.
Thanks.
_______________________________________________ Haskell-Cafe mailing list Haskell-C...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe