[Haskell-beginners] newtype with a typclass

Emmanuel Touzery etouzery at gmail.com
Mon Mar 18 19:18:46 CET 2013


Maybe this article can interest you:
http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/

I think a record syntax is probably the best match, the biggest mismatch
between your approach and the haskell way might be the haskell preference
for immutability.

Maybe you should check how such things are implemented in existing gui
libraries in haskell.

emmanuel
On 18 Mar 2013 19:12, "Răzvan Rotaru" <razvan.rotaru at gmail.com> wrote:

>
>
> 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
>> understand.
>>
>> 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
>> associates
>> allbery.b at gmail.com
>> ballbery at sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
> 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.
>
> Razvan
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130318/d9475767/attachment.htm>


More information about the Beginners mailing list