Ticket #1158 (closed enhancement: fixed)

Opened 6 years ago

Last modified 5 years ago

Widgets should implement Eq and Ord.

Reported by: guest Owned by: axel
Priority: trivial Milestone: 0.10.2
Component: general (Gtk+, Glib) Version: 0.9.12
Keywords: instance Eq Ord Cc:

Description

When using GTK+ from a typical imperative language such as C++, it's

occasionally useful to use the object identity of a widget: for instance, you might want to create a set of "main" windows and terminate the program only when all of them close. Since widgets are represented by pointers, this is straightforward, and they can be stored in any standard container class (such as std::set).

Unfortunately, the Haskell binding doesn't expose this information.

It would be nice if GTK+ objects had instances of Ord and Eq based on pointer identity. Then they could, e.g., be stored in Data.Set.Set objects.

(I know this can be worked around; it's just something that would

save a little trouble)

Daniel

Reported on Debian BTS: http://bugs.debian.org/520474

Change History

Changed 5 years ago by pgavin

  • owner changed from somebody to axel
  • milestone set to 0.10.2

I have some (purely pedantic) reservations with putting Widgets in Ord, but Eq should be fine.

Axel?

Changed 5 years ago by axel

  • status changed from new to closed
  • resolution set to fixed

Hm, Ord makes me hesitate a bit since it could lead to code that is compiled but doesn't make any sense, but the same holds for Eq if people think of an object as if it is a pure value (like a graphics context GC, for example). However, there is a general need, I think, to compare objects for pointer equality, for instance, when extracting the current widget from a notebook which needs to be compared to existing widgets.

So, I've amended the type hierarchy generator to add Ord and Eq instance for all types except those that have a noEq attribute in hierarchy.list (this is a new tag). I did this because ForeignPtr? and Ptr also have Eq and Ord instances. Thus, it must be good.

Note: See TracTickets for help on using tickets.