[Haskell-beginners] type hierarchies / records

Kim-Ee Yeoh ky3 at atamo.com
Thu Mar 14 18:58:59 CET 2013


On Thu, Mar 14, 2013 at 10:58 PM, Răzvan Rotaru <razvan.rotaru at gmail.com>wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130315/4a73ac74/attachment.htm>


More information about the Beginners mailing list