On Fri, Feb 20, 2009 at 3:10 AM, Robert Vollmert <rvollmert-li...@gmx.net>wrote:
> 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)) > tr = (fst *** fst) &&& (snd *** snd) > > diag :: (a -> a -> b) -> (a -> b) > diag f x = f x x diag = join -- for Monad (->) a, in Control.Monad.Instances > > 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 > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe