[Haskell-cafe] Re: Looking for pointfree version (Kim-Ee Yeoh) (02/12)

Robert Vollmert rvollmert-lists at gmx.net
Fri Feb 20 05:10:01 EST 2009


On Feb 20, 2009, at 06:07, Gene Arthur wrote:

>> Kim-Ee Yeoh said:
>> On the same note, does anyone have ideas
>> for the following snippet? Tried the pointfree
>> package but the output was useless.
>
>> pointwise op (x0,y0) (x1,y1) = (x0 `op` x1, y0 `op` y1)
>
> First sorry for the delay in getting to this.. been behind on
> projects so had some days of mail piled up.  Here is what
> I came up with, using one arrow operator,
> so you would have to import: Control.Arrow ((***)) at minimum
> to use this solution:
>
> pointfree ::
>    forall t t1 c. (t -> t1 -> c) -> (t, t1) -> (t, t1) -> (c, c)
>
> pointfree op  =
>      curry $ (\(a,b) -> a `op` b)  *** (\(a,b) -> a `op` b)
>
> examples of use, that were executed using:
>
> ghci -fglasgow-exts -farrows Control.Arrow
>
> *>pointfree (*) (3,5) (12,12)
>
> (15,144)

That's not quite what pointwise above does, though. The following  
works using (***):

tr :: ((a,b),(c,d)) -> ((a,c),(b,d))
tr ((x,y),(z,w)) = ((x,z),(y,w))

diag :: (a -> a -> b) -> (a -> b)
diag f x = f x x

pointfree :: (a -> b -> c) -> (a,a) -> (b,b) -> (c,c)
pointfree = curry . (. tr) . diag (***) . uncurry

Do tr or diag exist in the libraries?

Cheers
Robert



More information about the Haskell-Cafe mailing list