[Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-03 Thread tpledger
Nils Anders Danielsson wrote:
> A function like this has been suggested for the
> standard libraries a couple of times before.
> Someone suggested the name "on", which I quite
> like:
>
>   (*) `on` f = \x y -> f x * f y


Thanks!  I always wanted to be someone.  :-)

Here's the link.

http://www.haskell.org//pipermail/haskell-cafe/2004-December/007917.html

- Tom
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-03 Thread Nils Anders Danielsson
On Sun, 02 Apr 2006, "Jared Updike" <[EMAIL PROTECTED]> wrote:

> Something like "distribute fst (==)" where
>
>> distribute f op x y = f x `op` f y

A function like this has been suggested for the standard libraries a
couple of times before. Someone suggested the name "on", which I quite
like:

  (*) `on` f = \x y -> f x * f y

>> unionBy (distribute fst (==)) listOfPairs1 listOfPairs2

unionBy ((==) `on` fst) xs ys

I think on makes the code rather readable: union by equality on first.

-- 
/NAD

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-02 Thread Dean Herington

At 11:58 AM -0700 4/2/06, Jared Updike wrote:

Is there a common way (standard libs, higher order) to express the
lambda part below? It's not particulary complicated but I think it is
not higher-order enough


 unionBy (\x y -> fst x == fst y) listOfPairs1 listOfPairs2


Something like "distribute fst (==)" where


 distribute f op x y = f x `op` f y


would leave


 unionBy (distribute fst (==)) listOfPairs1 listOfPairs2


I imagine something involving Arrows and/or zip/curry/uncurry but I just
can't see it. Is this a case of trying to make something more complicated
than it is?

  Jared.


I think you've reached sufficient higher-order-ness.  Others on the 
list have offered your function in a slightly different form:



 f `on` g = \x y -> g x `f` g y
 unionBy ((==) `on` fst) listOfPairs1 listOfPairs2


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-02 Thread David Menendez
Jared Updike writes:

> Is there a common way (standard libs, higher order) to express the
> lambda part below? It's not particulary complicated but I think it is
> not higher-order enough
> 
> > unionBy (\x y -> fst x == fst y) listOfPairs1 listOfPairs2
> 
> Something like "distribute fst (==)" where
> 
> > distribute f op x y = f x `op` f y
> 
> would leave
> 
> > unionBy (distribute fst (==)) listOfPairs1 listOfPairs2
> 
> I imagine something involving Arrows and/or zip/curry/uncurry but I
> just can't see it. Is this a case of trying to make something more
> complicated than it is?

If you look at it in terms of folds over pairs,

cata (&) (x,y) = x & y   -- corresponds to uncurry
ana f g x = (f x, g x)   -- corresponds to (&&&)

Then you can de-forest:

hylo (&) f g x = f x & g x

-- hylo (&) f g == cata (&) . ana f g
--  == uncurry (&) . f &&& g
--
-- cata (&) == hylo (&) fst snd
-- ana f g  == hylo (,) f g

This seems remeniscent of pull-backs (or push-outs) in category theory,
but I don't know enough to say for certain.
-- 
David Menendez <[EMAIL PROTECTED]> | "In this house, we obey the laws
  |of thermodynamics!"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Distributing monadic(?) functions across dyadic functions

2006-04-02 Thread Jared Updike
Is there a common way (standard libs, higher order) to express the
lambda part below? It's not particulary complicated but I think it is
not higher-order enough

> unionBy (\x y -> fst x == fst y) listOfPairs1 listOfPairs2

Something like "distribute fst (==)" where

> distribute f op x y = f x `op` f y

would leave

> unionBy (distribute fst (==)) listOfPairs1 listOfPairs2

I imagine something involving Arrows and/or zip/curry/uncurry but I just
can't see it. Is this a case of trying to make something more complicated
than it is?

  Jared.
--
http://www.updike.org/~jared/
reverse ")-:"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe