
Hi! On Wed, Jul 27, 2011 at 09:47:14AM +1000, Jeff Lasslett wrote:
Also, if I understand correctly, solutions 1 & 2 will only produce one pair, whereas solution 3 (based on list comprehensions) will produce all pairs that sum to the total.
On 27 July 2011 07:33, Gary Klindt
wrote: sumCheck3 i as bs = not $ null [(x,y) | x <- as, y <- bs, x+y==i ]
Maybe I misunderstood you, but you aren't quite right. In third solution, *list comprehension* will produce all the pairs. But you're applying 'null' to it, and since everything in Haskell is lazy by default, only *one* pair will be produced. Just for your information: that's why it's always advised to use 'null' to check if list is empty. Newbies often try to do that in more obvious way: length list == 0 but that have very nasty consequence: to calculate length of the list, you should compute the value of each element. If you use null, only first (if any) element gets computed, and then null immediately returns. Ah, yes, one more note: first two solutions return pair that satisfies your task, while third solution will only return some Bool value indicating if such pair exists. -- Regards, Alexander Batischev 1024D/69093C81 F870 A381 B5F5 D2A1 1B35 4D63 A1A7 1C77 6909 3C81