[Haskell-beginners] FW: another list comprehesion error

Roelof Wobben rwobben at hotmail.com
Fri Jul 22 11:13:28 CEST 2011




----------------------------------------
> From: rwobben at hotmail.com
> To: haskell at phirho.com
> Subject: RE: [Haskell-beginners] another list comprehesion error
> Date: Fri, 22 Jul 2011 06:46:03 +0000
>
>
>
>
> ----------------------------------------
> > Date: Thu, 21 Jul 2011 23:40:52 +0200
> > From: haskell at phirho.com
> > To: beginners at haskell.org
> > Subject: Re: [Haskell-beginners] another list comprehesion error
> >
> > Hi!
> >
> > On 21.07.2011 21:29, Roelof Wobben wrote:
> > > roelof n x = [x | y<- [1..n]]
> >
> > Have you tried this?
> > What do you get for, say "roelof 4 5" ? Why?


 

I get [5,5,5,,5]
And that the right answer according to the exercise

> > 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.



> > A few suggestions (without guards):
> > The list of the first 5 natural numbers.
> > The list of the first 5 odd numbers.
> > The list of all pairs (a, b) where a,b > 0, a <= b and b <= 5
> >
> > Now you can try the last two with guards.


without guards



1) [x | x <- [1..5]]
2) cannot be done without guards and list comprehession generator [ 2,4 ..10] does not work
3) cannot be done withut guards and list comprehession because of the a<=b

with guards.


1) has no need for guards.
2) [x | x <-[1..10], even x]
3] [ (a,b) | a<- [1..4], b<- [1..5], a<=b]

Roelof

  		 	   		  


More information about the Beginners mailing list