🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #1098

Re: How do i approach this problem?

#1098
From: Sebastian Sylvan
Date: Mon, 17 Feb 2003 23:35
43 lines
3150 bytes
On Tue, 18 Feb 2003, Konrad Den Ende wrote:
> Now, i have wasted several layers of my keyboard to produce following
> amazing decencies:
> [ x:xs | xs <- ["123","456"] , x <- [head xs] ]
> It works as i wish and special thanks to mr. Sebastian S for pointing out
> that "head xs" is not a list, unless made being one.

That really isn't a nice way to write it =)
Why use the "drawn from" syntax on a list containing one element. Just do:
[ head xs : xs | xs <- ["123","456"] ]

> What i don't like is that the following doesn't work:
> [ x:xs | x <- [head xs] , xs <- ["123","456"] ]
> since i remember reading somewhere that Hasell doesn't have variables,
> but rather constants that get a value assigned upon execution, thus keeping
> it to the end of the time. Correct? If so, why the error. If no, who to
> kill?

I _think_ that list comprehensions are just syntactic sugar for the list
monad. Don't worry about that now, just remember that the lists are
"traversed" from left to right. Which means that the above says "for each
x in the list [head xs], take each xs in ["123","456"] and do x:xs".
Now this doesn't make sense because the list that x is drawn from is
defined using something which isn't defined yet!
The qualifiers in the list comprehensions must be written down left to
right, because they "variables" are really just short hands for "every
element in the list". This is evaluated left to right so you can define a
list using a variable that is drawn from a list to the left of it.


--

 ----------------------------------------
|  Sebastian Sylvan                      |
|  ICQ: 44640862                         |
|  Tel: 073-6818655 / 031-812 817        |
|                                        |
|  <=================================>   |
|  |Det finns 10 sorters m�nniskor.  |   |
|  |De som f�rst�r det bin�ra tal-   |   |
|  |systemet och de som inte g�r det.|   |
|  <=================================>   |
 ----------------------------------------
Technical Details
Message-ID: <Pine.GSO.4.10.10302180030010.11586-100000@licia.dtek.chalmers.se>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!uio.no!news.netg.se!dd.chalmers.se!licia.dtek.chalmers.se!sylvan
References: <b2rbba$6dc$1@news.gu.se> <Pine.GSO.4.10.10302172105080.18198-100000@licia.dtek.chalmers.se> <b2rpuk$cn6$1@news.gu.se>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 107f24,a907e0b23c6eca41
X-Google-Attributes: gid107f24,public
X-Google-Thread: 10f6e0,a907e0b23c6eca41
X-Google-Attributes: gid10f6e0,public
X-Google-ArrivalTime: 2003-02-17 15:40:02 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!uio.no!news.netg.se!dd.chalmers.se!licia.dtek.chalmers.se!sylvan
From: Sebastian Sylvan <sylvan@dtek.chalmers.se>
Newsgroups: comp.lang.functional,cth.dtek.general
Subject: Re: How do i approach this problem?
Date: Tue, 18 Feb 2003 00:35:23 +0100
Organization: Chalmers University of Technology, Sweden
Lines: 44
Message-ID: <Pine.GSO.4.10.10302180030010.11586-100000@licia.dtek.chalmers.se>
References: <b2rbba$6dc$1@news.gu.se> <Pine.GSO.4.10.10302172105080.18198-100000@licia.dtek.chalmers.se> <b2rpuk$cn6$1@news.gu.se>
NNTP-Posting-Host: licia.dtek.chalmers.se
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT
In-Reply-To: <b2rpuk$cn6$1@news.gu.se>