[Haskell-beginners] newtype with a typclass
razvan.rotaru at gmail.com
Mon Mar 18 19:10:19 CET 2013
On 18 March 2013 18:34, <beginners-request at haskell.org> wrote:
> Not directly, no. It is possible to use existentials to do this ? at the
> cost that you lose the ability to do anything but what you have declared
> about it. For example, if you were to use this to make a map of Show-able
> values, the *only* thing you can do with the value is invoke "show" on it
> (in particular: you cannot pull out the value directly, because the only
> thing you know about it is that "show" works on it; you otherwise have no
> idea what it is!). And with such a value, referential transparency means
> there is no difference between this and storing the *result* of invoking
> "show" on it (that is, a String) instead, and laziness means that it may
> well actually store a thunk that will invoke "show" when the value is
> needed instead of computing and storing the value, so that there is in fact
> no difference between the two except that the type is much more complicated
> and both the type and the code are correspondingly more difficult to
> What problem are you trying to solve by obfuscating things in this manner?
> Also note that most times when someone is trying to do this, they have
> confused typeclasses with OOP; they are not, and trying to treat them as
> such *will* lead you into dead ends.
> brandon s allbery kf8nh sine nomine
> allbery.b at gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
Well, I need something similar to Java interfaces. Or at least this is my
current way of thinking about the problem. I am trying to build some types
for GUI Widgets, and I would like to use Maps to keep their properties.
It's meant to replace the record syntax, which I find unusable because of
the name clash. I also would like to have fast non-destructive update of
this type, by using structural sharing, and Maps as good for this.
So, for example a Button would have an id, a label and function for the
onclick event, and these three values should be kept in a map, with the
keys "id", "label" and "onclick".
It's true that keeping Show-able values is not enough, since I won't be
able to call the onclick function. Unfortunately, I have no idea how to do
this as well.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners