Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Heterogeneous Lists (harry)
   2. Re:  Heterogeneous Lists (Brent Yorgey)
   3. Re:  Heterogeneous Lists (Brent Yorgey)
   4. Re:  Heterogeneous Lists (Mateusz Kowalczyk)
   5. Re:  Heterogeneous Lists (harry)
   6. Re:  Heterogeneous Lists (Brandon Allbery)
   7. Re:  Heterogeneous Lists (Mateusz Kowalczyk)
   8. Re:  Heterogeneous Lists (Benjamin Edwards)


----------------------------------------------------------------------

Message: 1
Date: Tue, 28 May 2013 13:41:55 +0000 (UTC)
From: harry <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Magnus Therning <magnus <at> therning.org> writes:

> Just to make sure... I guess you've already read
> http://www.haskell.org/haskellwiki/Heterogenous_collections right?

Yes, I'm asking why Haskell doesn't allow this directly. I'm already using a
workaround.




------------------------------

Message: 2
Date: Tue, 28 May 2013 09:49:24 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, May 28, 2013 at 07:36:13AM +0000, harry wrote:
> Every OO language which supports generics allows a declaration such as
> List<Show> alist, where Show is an interface. Any type implementing Show can
> be put in alist, and any Show operation can be performed on the alist's
> members. No casts, wrappers, or other special types and plumbing are needed.
> 
> Why isn't it possible to do this directly in Haskell?

I am not sure what you mean by asking "why".  If you are simply
implying that this is stupid and Haskell *should* be able to do this
directly, then I would say that you need to spend more time learning
to think through the lens of the abstractions Haskell *does* give you,
and stop trying to think through an OOP lens.  I can count on one
finger the number of times I have wanted a heterogeneous collection
like this --- it was a long time ago, and I was wrong.

On the other hand, if you sincerely want to know why, it is simply
that this kind of feature does not fit nicely within the space of the
design decisions that were made when creating Haskell, for example:
(1) All the elements of a list must have the same type.  (2) A type
class cannot be used as a type.  (3) Haskell has no subtyping.  And
there are good reasons behind these decisions as well.  For example,
subtyping makes type inference nigh impossible.

-Brent



------------------------------

Message: 3
Date: Tue, 28 May 2013 09:50:21 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Tue, May 28, 2013 at 01:41:55PM +0000, harry wrote:
> Magnus Therning <magnus <at> therning.org> writes:
> 
> > Just to make sure... I guess you've already read
> > http://www.haskell.org/haskellwiki/Heterogenous_collections right?
> 
> Yes, I'm asking why Haskell doesn't allow this directly. I'm already using a
> workaround.

This is probably not a good idea.  Instead, why don't you explain to
us what you are trying to accomplish, and perhaps we can suggest a
better way that does not require heterogeneous lists?

-Brent



------------------------------

Message: 4
Date: Tue, 28 May 2013 14:50:21 +0100
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 28/05/13 14:41, harry wrote:
> Magnus Therning <magnus <at> therning.org> writes:
> 
>> Just to make sure... I guess you've already read 
>> http://www.haskell.org/haskellwiki/Heterogenous_collections
>> right?
> 
> Yes, I'm asking why Haskell doesn't allow this directly. I'm
> already using a workaround.
> 
> 
> _______________________________________________ Beginners mailing
> list [email protected] 
> http://www.haskell.org/mailman/listinfo/beginners
> 
Simply because Haskell's lists are a homogeneous data structure by nature.

Consider:
data List a = Nil | Cons a List

It doesn't do heterogeneous lists by default because it was never
meant to. I don't see where the disappointment comes from. It's the
same in majority of typed languages. I don't see why you would expect
to be able to make have a heterogeneous list because you can do it
with interfaces in some other language. To begin with, typeclasses are
not interfaces.

Just so you know, you're probably doing it wrong if you're using `a
workaround' to have a heterogeneous list.
- -- 
Mateusz K.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBAgAGBQJRpLYdAAoJEM1mucMq2pqXzGIQAK4YapHZdtTdfUbFCZc90MF6
KbE5NmXswaKfgf+OU5Cs7fGG0dZahmeAEhFpZBVEUlnKXGT9hGiFQj7cm/4hK881
kGHWq5WlqGuzdnD9iTEG+IcLsqXQA1ZArObOFB2VL7dSzQHPhKHpnIshzID4osN6
QBo7fYvQ9H2Ng0sf5Cuo88ck0VGxKxvDPG8cg/6SpjH1EdPg3LlPiEYnZJoKbDnM
G82IFctzANYuFbIXclD/DK6dlv/6newAR1Q5zXCD9ZQJv7y2z0mhA4gjbb4fUNGb
3y0wkj+srC6skC/1g871cQRC6u0aRSdGKYZIs2SwlKKFwUGftLlnq/KQukYuYuWi
HB8H+jm3/tQDZEius9umVlQN6c56pglh+gY8p9bnAqOsw8gfSeM5qlEggSCs5wIh
BpQBEOANMUKZRiRGrmx2FEl8IwdRcf5LUStFiI0EpabZDTpRQVRuG3K/LZpZS0em
UPOfP/X0jDZAhxb/iiR91F+DnpzWrMkteP4mqQ9GpqY2RmXY3jw3B/1uC41mX17v
NWfUULp4rRtcMPn2OvXYn28r3sCCO5D78rcGk2uv7Mmnb2HFq99XiaQG3Q7pzaB0
O4wePLuwFPZqefFuIl8WM68qjYFBeUJkOR3ik3Q1V2SftLMy8kFnDdz80DykOODw
2Sw+0P1Dyxk45ENu+Fry
=rpvr
-----END PGP SIGNATURE-----



------------------------------

Message: 5
Date: Tue, 28 May 2013 14:00:46 +0000 (UTC)
From: harry <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Brent Yorgey <byorgey <at> seas.upenn.edu> writes:

> On the other hand, if you sincerely want to know why, it is simply
> that this kind of feature does not fit nicely within the space of the
> design decisions that were made when creating Haskell, for example:
> (1) All the elements of a list must have the same type.  (2) A type
> class cannot be used as a type.  (3) Haskell has no subtyping.  And
> there are good reasons behind these decisions as well.  For example,
> subtyping makes type inference nigh impossible.

Yes, (2) is what I don't understand. I recently ran into this with a GUI
application, where I needed to process a list of widgets that were members
of the same typeclass, but I had to wrap them all because they were
different types.

So so rephrase my question, why can't type classes be used as a type? Is
this an implementation issues, or is there a semantic problem with this?
Creating an existential type and packing all the values seems like busy work
which shouldn't be necessary, or at least something that the compiler should
be doing for me.




------------------------------

Message: 6
Date: Tue, 28 May 2013 10:30:03 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cakfcl4wd-ct410bdskqm+qocbue8fdo6aoemawu2_38n_gn...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, May 28, 2013 at 10:00 AM, harry <[email protected]> wrote:

> So so rephrase my question, why can't type classes be used as a type? Is
> this an implementation issues, or is there a semantic problem with this?
> Creating an existential type and packing all the values seems like busy
> work
> which shouldn't be necessary, or at least something that the compiler
> should
> be doing for me.


Haskell is strongly typed; if you want to throw out all the type
information, you must tell if explicitly (which is what the existential
does). This comes at a price, of course: once you've thrown out the type
information, you can't get it back.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130528/24565418/attachment-0001.htm>

------------------------------

Message: 7
Date: Tue, 28 May 2013 15:28:44 +0100
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 28/05/13 15:00, harry wrote:
> Brent Yorgey <byorgey <at> seas.upenn.edu> writes:
> 
>> On the other hand, if you sincerely want to know why, it is
>> simply that this kind of feature does not fit nicely within the
>> space of the design decisions that were made when creating
>> Haskell, for example: (1) All the elements of a list must have
>> the same type.  (2) A type class cannot be used as a type.  (3)
>> Haskell has no subtyping.  And there are good reasons behind
>> these decisions as well.  For example, subtyping makes type
>> inference nigh impossible.
> 
> Yes, (2) is what I don't understand. I recently ran into this with
> a GUI application, where I needed to process a list of widgets that
> were members of the same typeclass, but I had to wrap them all
> because they were different types.
> 
> So so rephrase my question, why can't type classes be used as a
> type? Is this an implementation issues, or is there a semantic
> problem with this?
Type classes can't be used as types because they are not types. It's
just that simple. To achieve what you want you actually create a new
type (with `data') and put a type class constraint on the types it
accepts. We can then use that type for our collection.

> Creating an existential type and packing all the values seems like
> busy work which shouldn't be necessary, or at least something that
> the compiler should be doing for me.
Yes, it is in fact busy work and yes, it could probably be done for
you by the compiler. I imagine the reason it isn't is simply because
forcing heterogeneous collections where only homogeneous ones were
intended is usually a sign of the fact that you are doing it wrong and
usually there's a better solution. Putting in direct support for it in
the compiler would just make the compiler more complex and effectively
encourage bad programming. It's just not something that comes up often
enough to warrant a compiler extension.

- -- 
Mateusz K.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBAgAGBQJRpL8cAAoJEM1mucMq2pqXFiMP/jaK3i6sW+R7aoKqp3UwjgRM
SSdD1zEpcPtMRwoucpW0GDk+gjtIvqTcrpo5THD6w59G1Pwvm/8G+852xHfdPVUs
NmpYtz1an4mGeJZmz7One0UbX+Bh7mz83E/fLkUJ4FrBXF7q9XFVPwhkRb+5F4Yd
BovYSPwmGsUslXc785UE2J3G/nPW61jtw+w0k+SRuD7wJd/0JQO54rp3PQt5udO+
GF022pOqB+IWxIAqaZ+CEPiEotrGLe6tJzvE8J0vgkcgTpGrumRyJRz/yRc0foXi
FuOgRPr1dgaajanMOcaapWkf0aE1RxfIR0iDWgcQZYpPlU6nTz9XhQZ0216udUHr
px5PnpFSFmVHdtWxdMEjY5zBlV51TwUZm01kQQ+mBO4cqsHJNEuSFSpcOoMddH/X
P/s/dTUtWp01cjSCkxahDCltvuDNmmOGT5kfmZ22YdOGTdbsjCVY/tHM6WFDb8OB
6j2a8YovorskWx5Mpw+3GS5VOn7KgDvKXoRvCQL8KvRLBlekVGHjXRz9kQRTGQwW
KV9WcNQU46mw1tyLJaD5zbKko8HvGUc4I8DdbtMLnJ3KQuiTQIp677QyoGFZcE1C
USyvG3E+lsXU9fBw3GpxPfSQLM0t3waL4tMdKXt0urIidSJdpIPNJrS+SICxF62Z
FpJ3V8/U7lnjo0z6/Iy0
=yKxA
-----END PGP SIGNATURE-----



------------------------------

Message: 8
Date: Tue, 28 May 2013 15:37:28 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] Heterogeneous Lists
To: haskellbeginners <[email protected]>
Message-ID:
        <CAN6k4nh=eoclut8o1dfv6yp++v7sajxkeohko6j3baep3wo...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Might be worth reading
http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/

Especially in the context of guis and widgets.

Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130528/93f5198b/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 59, Issue 37
*****************************************

Reply via email to