[Haskell-cafe] gtk2hs question - derive SettingsWindow from Window

Cetin Sert cetin.sert at gmail.com
Fri Dec 12 15:03:01 EST 2008


Hi all,

For a network manager of sorts I'm working on, I want to derive a
SettingsWindowClass from the WindowClass present in Gtk2Hs:

I want (the) instance(s) of the SettingsWindowClass to have a field to store
connection settings:

1) Is it safe to do it like this?

class WindowClass self ⇒ SettingsWindowClass self where
  settingsWindowGetSettings :: self → IO [ConnectionSetting]
  settingsWindowSetSettings :: self → [ConnectionSetting] → IO ()

newtype SettingsWindow = SettingsWindow (Window,[ConnectionSetting])

mkSettingsWindow = SettingsWindow
unSettingsWindow (SettingsWindow o) = o

settingsWindowNew :: IO SettingsWindow
settingsWindowNew = do
  win ← windowNew
  return $ mkSettingsWindow (win,[])

2) Is this a common practice in gtk2hs usage?
3) And will GC properly free the memory allocated for the Window object? How
is this ensured, do ForeignPtr's always call delete on the underlying C ptr
when they get garbage collected?

Best Regards,
CS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081212/14b1fe42/attachment-0001.htm


More information about the Haskell-Cafe mailing list