Re: Common GUI API : What would the code look like?
David Sankel <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.gui |
|---|---|
| Message-ID | <[email protected]> |
--- Glynn Clements <[email protected]> wrote: > > > 3. Personally, I would prefer a generic widget > > > creation function, > > > rather than a different function for each type > of > > > widget. E.g. Xt has > > > XtCreateWidget(), with the widget class being > passed > > > as an argument. > > > A more Haskell-ish approach would be to use > > > typeclasses, e.g.: > > > > > > class Widget a where > > > create :: String -> a -> [Property] -> IO a > > > -- create name parent properties = ... > > That should be: > > create :: (Widget b) => String -> b -> [Property] > -> IO a > > A widget's parent must be a widget, but not > necessarily the same type > of widget. > Ahh, I thought you wanted to create widgets based on the String parameter. So in the following code, you would get an ambiguity error, right? do -- mainWindow defined above a <- create "Some_Button" mainWindow [ label := "Okay" ] runGUI mainWindow -- or whatever it is. The system does not know if a is a button, a label, or whatever. It would have to look like this to remove the ambiguity do -- mainWindow defined above a <- create "Some_Button" mainWindow [ label := "Okay" ] :: Button runGUI mainWindow -- or whatever it is. It seems like this would defeat the purpose of having a generic create function since Button needs to be in there somewhere. Although, I do find your argument very credible. David J. Sankel