How do I handle clicks on a listBox in Haskells gi
I am experimenting with using Gtk and Haskell. And I got stuck. This link shows my experiments. https://github.com/bigos/my-haskell-gtk-3-tutorial/blob/master/5-layout-containers.org#edit-the-source-2
I am trying to print the index of clicked list box row. The following code gives me a type error that I do not understand.
onListBoxRowSelected listbox2 (row -> putStrLn (listBoxRowGetIndex row))
I need an example where I can see how someone can properly handle the click events on the listBox rows.
the error message
Required ancestor 'GI.Gtk.Objects.ListBoxRow.ListBoxRow' not found for type 'Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow'. • In the first argument of 'putStrLn', namely '(listBoxRowGetIndex row)' In the expression: putStrLn (listBoxRowGetIndex row) In the second argument of 'onListBoxRowSelected', namely
Callback argument type is Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
. It could be Nothing
if nothing is selected. listBoxRowGetIndex
has polymorphic type for its argument, so it tries to find instance for Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
, but there is no such instance. Minimal working code is
onListBoxRowSelected listbox2 ((Just row) -> listBoxRowGetIndex row >>= print)
But it is better to handle Nothing
case properly considering application logic.
上一篇: 有什么区别。 (点)和$(美元符号)?