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 a

Re: [Haskell-cafe] defining mapPairs function

2007-09-01 Thread Ross Paterson
On Sat, Sep 01, 2007 at 04:59:50AM -0700, Alexteslin wrote: > 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 amen

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 try

Re: [Haskell-cafe] defining mapPairs function

2007-08-30 Thread Dan Weston
That's just a minor change of plumbing: import Control.Arrow((***),(&&&),(>>>),app) import Data.Maybe(catMaybes,maybeToList) mapPair :: (a -> a -> a) -> [a] -> [a] mapPair = curry mp where mp = (((zipWith >>> uncurry) *** -- (inter-elem function (id &&& tail) >>> -- ,d

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

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

Re: [Haskell-cafe] defining mapPairs function

2007-08-29 Thread Dan Weston
Sometimes it is interesting to approach things from a different perspective. The goofyness below will have been useful if it interests you in point-free programming. And anyway, I sure had a good time writing it... I am composing several common Haskell idioms: 1) When adjacent list elements a

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 rea

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

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 stand

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,

[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 exampl