[Haskell-beginners] another list comprehesion error
Roelof Wobben
rwobben at hotmail.com
Fri Jul 22 12:37:30 CEST 2011
Oke,
Thanks.
I was wondering one thing and I think at this moment too difficult for me,
But can you with a list comprehession read one list and alter another list.
For example:
You have a list of numbers
Now you would calculate the average value and put the outcome in another list.
Just wondering so you have to say it can or cannot be done.
Roelof
----------------------------------------
> Date: Fri, 22 Jul 2011 11:31:07 +0200
> From: haskell at phirho.com
> To: beginners at haskell.org
> Subject: Re: [Haskell-beginners] another list comprehesion error
>
> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list