Hi,

On Github, Jeremy O'Donoghue provides wx example code. From his collection I am trying to modify Layout.hs [1] to permit a variable number, rather than a fixed number, of text entry boxes. I shrank the program, mostly by removing features, until it was this:

  main = start $ do
    f      <- frame  [text := "Layout test"]
    p      <- panel  f []
    xinput <- textEntry p [text := "100"]
    yinput <- textEntry p [text := "100"]
    myVar <- varCreate [xinput,yinput]
    set f [ layout := container p $ margin 10 $
      column 5 [boxed "coordinates" (grid 5 5
          [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing
        ) ] ]                                         
    return ()

I want to replace the line marked "replacing". Rather than hard-coding the number of text entry boxes (2), I want it to deal with a mutable collection of them, in myVar.

I tried this:
  [ fmap (\e -> hfill $ widget e) $ varGet myVar ]
and got this error:
  Layout.hs:23:11:
      Couldn't match type `IO' with `[]'
      Expected type: [Layout]
        Actual type: IO Layout
      In the expression: fmap (\ e -> hfill $ widget e) $ varGet myVar
      In the third argument of `grid', namely
        `[fmap (\ e -> hfill $ widget e) $ varGet myVar]'
      In the second argument of `boxed', namely
        `(grid 5 5 [fmap (\ e -> hfill $ widget e) $ varGet myVar])'

So then I tried something I thought would be equivalent:
  [[ (hfill $ widget e) | e <- (varGet myVar)]]
and got a different error:
  Layout.hs:23:39:
      Couldn't match expected type `[w0]'
                  with actual type `IO [TextCtrl ()]'
      In the return type of a call of `varGet'
      In the expression: (varGet myVar)
      In a stmt of a list comprehension: e <- (varGet myVar)

I kind of understand the problem is that when I varGet myVar, I end up with type IO Layout, rather than type Layout, but I don't know what to do about it.

Thanks,
Jeff


[1] https://github.com/jodonoghue/wxHaskell/blob/master/samples/wx/Layout.hs