[Haskell-beginners] another list comprehesion error

Thomas haskell at phirho.com
Fri Jul 22 11:31:07 CEST 2011


On 22.07.2011 08:46, Roelof Wobben wrote:

>> Now try this instead:
>> roelof' n = [x | x<- [1..n]]
>> What do you get for "roelof' 4" ?
> A error message that a instance of print is missing.

Then you have a typo somewhere...

>> Now you can try the last two with guards.

> 2) cannot be done without guards and list comprehession  generator [ 2,4 ..10] does not work

Sure it can:
[ 2*x-1 | x <- [1..5]]
and even easier:
[1,3..10]
or, better still (but not only a list comprehension any more):
take 5 [1, 3..]

> 3) cannot be done withut guards and list comprehession because of the a<=b

This, too, can be done:
[ (b, a) | a <- [1..5], b <- [1..a]]

Regards,
Thomas



More information about the Beginners mailing list