[Haskell-cafe] Re: Query on list comprehension

2009-03-20 Thread Jon Fairbairn
Richard O'Keefe o...@cs.otago.ac.nz writes:

 The problem we were asked about was specifically
 a
 aa
 aaa
 The code (iterate ('a':) \n) does not give the right answer.
 It's not just that it produces an infinite list instead of three
 strings, it doesn't even start with the right string.  It starts
 with \n when we need a\n.

It was impossible to determine that from the question.

 To produce the specified output using that pattern, you need
 (take 3 . tail . iterate ('a':)) \n

take 9, surely?

 or any of several other alternatives.

 The original poster also didn't ask what is the best way to do
 this, but specifically asked about doing it with list
 comprehension.  Presumably this was an attempt to understand list
 comprehension better.

Perhaps, but as the OP didn't follow up to the message where
I said that it wasn't clear what the question was, by the
time Henning posted, I think he was justified in
generalising the question and taking the answer further.
This café is for discussion; it's not a suitable place for
asking a question, copying out the answer and disappearing
without further comment.

-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Query on list comprehension

2009-03-19 Thread Jon Fairbairn
Henning Thielemann lemm...@henning-thielemann.de writes:

 On Tue, 17 Mar 2009, Melanie_Green wrote:

 What are the limitations of list comprehension. I want to use
 listcomprehension to output the pattern below. So a mixture of a's and
 newline characters. The part im stuck at is creating arguments in the
 listcomprehension to stop at some point then execute next loop. Is it even
 possible to create the pattern below purely from list comprehension.Thankyou
 in advance.

 a
 aa
 aaa

 iterate ('a':) \n

Game to Henning Thielemann!

-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2009-01-31)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Query on list comprehension

2009-03-19 Thread Richard O'Keefe

The problem we were asked about was specifically
a
aa
aaa
The code (iterate ('a':) \n) does not give the right answer.
It's not just that it produces an infinite list instead of three
strings, it doesn't even start with the right string.  It starts
with \n when we need a\n.

To produce the specified output using that pattern, you need
(take 3 . tail . iterate ('a':)) \n
or any of several other alternatives.

The original poster also didn't ask what is the best way to do
this, but specifically asked about doing it with list
comprehension.  Presumably this was an attempt to understand list
comprehension better.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Jon Fairbairn
Melanie_Green jac_legend_...@hotmail.com writes:

 What are the limitations of list comprehension. I want to use
 listcomprehension to output the pattern below. So a mixture of a's and
 newline characters. The part im stuck at is creating arguments in the
 listcomprehension to stop at some point then execute next loop. Is it even
 possible to create the pattern below purely from list comprehension.Thankyou
 in advance. 

 a
 aa
 aaa

I'm not clear what you mean by the question. Why do you want
to use list comprehensions? What if they aren't the best way
of getting the result you want?

You can write 

[a | b - [replicate n 'a' | n - [1..]], a - b ++ \n] 

but does that replicate fail to meet your specification?
If not, you can replace it with another list comprehension
like this:

[a | b - [['a'| m - [1..n]] | n - [1..]], a - b ++ \n]

but at this point, comprehension is not what most people
would get from reading the code. I'd say it was clearer to
write

concat [replicate n 'a' ++ \n | n - [1..]]





-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2009-01-31)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Yitzchak Gale
Melanie_Green writes:
 I want to use listcomprehension to output the pattern below...

Jón Fairbairn wrote:
 Why do you want to use list comprehensions?
 What if they aren't the best way of getting the
 result you want?

unlines . tail . inits . repeat $ 'a'

 concat [replicate n 'a' ++ \n | n - [1..]]

Or:

unlines [replicate n 'a' | n - [1..]]

-Yitz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Kalman Noel
Jon Fairbairn schrieb:
 Melanie_Green jac_legend_...@hotmail.com writes:
 What are the limitations of list comprehension. [...]
 a
 aa
 aaa
 
 I'm not clear what you mean by the question. Why do you want
 to use list comprehensions? What if they aren't the best way
 of getting the result you want?
 
 You can write 
 
 [a | b - [replicate n 'a' | n - [1..]], a - b ++ \n] 
 
 but does that replicate fail to meet your specification?

Since we're »holfing« again:

fix $ \xs - [ 'a':xs | xs - []:xs ]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe