Re: [Haskell-cafe] defining mapPairs function

2007-09-01 Thread Alexteslin
Brent Yorgey wrote: On 8/29/07, Alexteslin [EMAIL PROTECTED] wrote: Hello, I just came across with this question on the exam and can not think of implementing it. Wait, is this an exam for a class you're taking? Or just a problem from an exam that you're trying to solve for

Re: [Haskell-cafe] defining mapPairs function

2007-09-01 Thread Brent Yorgey
On 9/1/07, Alexteslin [EMAIL PROTECTED] wrote: Hi, It is the former, but I sat an exam and trying to discuss my exam answers which will make no difference to what so ever to an exam, as an exam duration was 1.5 hours. Which means that no matter how much i would like to try to amend my

Re: [Haskell-cafe] defining mapPairs function

2007-08-30 Thread Devin Mullins
That's great (really, thank you for such a fun example of Arrow programming), but isn't the (*) on line two of mapPair supposed to be a point? How would you make a point-less version of mapPair that actually had the type signature (a-a-a)-[a]-[a]*? (For that matter, /would/ you?) Devin *

[Haskell-cafe] defining mapPairs function

2007-08-29 Thread Alexteslin
Hello, I just came across with this question on the exam and can not think of implementing it. mapPair :: (a - a - a) - [a] - [a] such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...] and if the list contains an odd number of elements, the last one is kept unchanged, for example

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Alexteslin
Alexteslin wrote: Hello, I just came across with this question on the exam and can not think of implementing it. mapPair :: (a - a - a) - [a] - [a] such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...] and if the list contains an odd number of elements, the last one

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Neil Mitchell
Hi Alexteslin, I just came across with this question on the exam and can not think of implementing it. mapPair :: (a - a - a) - [a] - [a] such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...] I would implement this using direct recursion. As a starting point, the standard

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Neil Mitchell
Hi mapPairs :: (a - a - a) - [a] - [a] mapPairs f [x] = [x] mapPairs f [] = [] mapPairs f (x:xs) = f x (head xs) : mapPairs f (tail xs) It looks like it works, but you can get a better version by changing the last line: mapPairs f (x:y:zs) = ... - left as an exercise, but no need for head

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Brent Yorgey
On 8/29/07, Alexteslin [EMAIL PROTECTED] wrote: Hello, I just came across with this question on the exam and can not think of implementing it. Wait, is this an exam for a class you're taking? Or just a problem from an exam that you're trying to solve for fun? If the former, it really

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Max Vasin
2007/8/30, Neil Mitchell [EMAIL PROTECTED]: Hi mapPairs :: (a - a - a) - [a] - [a] mapPairs f [x] = [x] mapPairs f [] = [] mapPairs f (x:xs) = f x (head xs) : mapPairs f (tail xs) It looks like it works, but you can get a better version by changing the last line: mapPairs f (x:y:zs)