type hierarchies / records

Dear Haskelleers, I suspect my problem has been discussed many times and under many forms, so please don't shoot me for asking. I could not find an acceptable solution yet, and beeing as stubborn as i am, I still hope the solution is eluding me because of my poor haskell knowlegde. So here I am posting my question on this mailing list. Basically I am trying to GUI Widgets using haskell types (Buttons, Textfields, etc.). 1/ Using Records is not acceptable because of the name clashes between attribute names. I could use prefixes and write functions in typeclasses for accessor, but it's ugly and a lot of work. 2/ I decided to keep the attributes in Maps, so basically a textfield would be data Textfield = Textfield (Map.Map TextfieldProps String) The problem is: how to define TextfieldProps? It should be something like: data TextfieldProps = Id | Label | Value But then, buttons also have Id's and labels. So following is not accepted anymore: data ButtonProps = Id | Label | OnClick Ideas and suggestions are much appreciated. Thank You, Răzvan

On Thu, Mar 14, 2013 at 10:58 PM, Răzvan Rotaru
2/ I decided to keep the attributes in Maps, so basically a textfield would be
data Textfield = Textfield (Map.Map TextfieldProps String)
Is defining data here even necessary? Even newtype seems superfluous. A plain "shorthand" type synonym surely fits the bill?
The problem is: how to define TextfieldProps? It should be something like:
data TextfieldProps = Id | Label | Value
But then, buttons also have Id's and labels. So following is not accepted anymore:
data ButtonProps = Id | Label | OnClick
Perhaps data TextfieldProps = TextId | TextLabel | TextValue -- and similarly for ButtonProps? I confess to not fully understanding the GUI modelling attempted here, which isn't to say that you aren't on the right track. To help you and help us help you better, one approach known to be successful is to sketch out the code (better yet, the type signatures!) of what you'd like to write, e.g. how are TextfieldProps and ButtonProps used? What functions act on them? -- Kim-Ee
participants (2)
-
Kim-Ee Yeoh
-
Răzvan Rotaru