2

In Gtk2hs there is the Graphics.UI.Gtk.ModelView.CustomStore module, which includes a data type containing a collection of functions, TreeModelIface. It contains a bunch of functions for navigating around a user-defined tree type where the location is stored as aTreeIter. So one of the member functions is:

treeModelIfaceIterNext :: TreeIter -> IO (Maybe TreeIter)

This returns the TreeIter associated with the next sibling node, if there is one. Simple enough. But the following member function is:

treeModelIfaceIterChildren :: Maybe TreeIter -> IO (Maybe TreeIter)

This takes a Maybe TreeIter instead of a simple TreeIter. The documentation doesn't say why, or what an argument of Nothing is used for.

Questions:

  1. Why this variation of argument types?

  2. What should treeModelIfaceIterChilren iface Nothing return?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Paul Johnson
  • 17,438
  • 3
  • 42
  • 59

1 Answers1

2

It's been sometime since I used the TreeModelIface interface, but if I remember correctly, it all has to do with the root (or top-level) nodes of the tree. So treeModelIfaceIterChilren iface Nothing is used to retrieve them since they have no parent. This is not an issue when you are iteration over the siblings with treeModelIfaceIterNext. In other words, to traverse the entire tree, treeModelIfaceIterChilren iface Nothing is your starting point, and the you succesively call treeModelIfaceIterNext and treeModelIfaceIterChilren (with a Just value).

redneb
  • 21,794
  • 6
  • 42
  • 54