如何处理 Haskells gi-gtk 库中列表框的点击
How do I handle clicks on a listBox in Haskells gi-gtk library
我正在尝试使用 Gtk 和 Haskell。我卡住了。 link 展示了我的实验。
https://github.com/bigos/my-haskell-gtk-3-tutorial/blob/master/5-layout-containers.org#edit-the-source-2
我正在尝试打印单击的列表框行的索引。下面的代码给我一个我不明白的类型错误。
onListBoxRowSelected listbox2 (\row -> putStrLn (listBoxRowGetIndex row))
我需要一个例子,我可以看到有人如何正确处理列表框行上的点击事件。
错误信息
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
回调参数类型为 Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
。如果未选择任何内容,则可能是 Nothing
。 listBoxRowGetIndex
的参数具有多态类型,因此它试图为 Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
找到实例,但没有这样的实例。最小工作代码是
onListBoxRowSelected listbox2 (\(Just row) -> listBoxRowGetIndex row >>= print)
但考虑到应用程序逻辑,最好妥善处理 Nothing
案例。
我正在尝试使用 Gtk 和 Haskell。我卡住了。 link 展示了我的实验。 https://github.com/bigos/my-haskell-gtk-3-tutorial/blob/master/5-layout-containers.org#edit-the-source-2
我正在尝试打印单击的列表框行的索引。下面的代码给我一个我不明白的类型错误。
onListBoxRowSelected listbox2 (\row -> putStrLn (listBoxRowGetIndex row))
我需要一个例子,我可以看到有人如何正确处理列表框行上的点击事件。
错误信息
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
回调参数类型为 Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
。如果未选择任何内容,则可能是 Nothing
。 listBoxRowGetIndex
的参数具有多态类型,因此它试图为 Maybe GI.Gtk.Objects.ListBoxRow.ListBoxRow
找到实例,但没有这样的实例。最小工作代码是
onListBoxRowSelected listbox2 (\(Just row) -> listBoxRowGetIndex row >>= print)
但考虑到应用程序逻辑,最好妥善处理 Nothing
案例。