[Haskell-cafe] Newbie type question for wxHaskell learner
Daniel Fischer
daniel.is.fischer at googlemail.com
Fri Jan 7 19:29:31 CET 2011
On Friday 07 January 2011 19:01:43, b1g3ar5 wrote:
> 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.
Depends on the semantics of panel, maybe
do whatever
p <- panel nb []
es <- mapM (\x -> textCtrl p [text := contents x]) my_list
moreWith es
does what you want. If panel has side effects you need for every item in
the list,
do whatever
es <- mapM (\x -> panel nb [] >>=
\p -> textCtrl p [text:=contents x]) my_list
moreWith es
ought to do it.
More information about the Haskell-Cafe
mailing list