Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Eric Rasmussen
Might not be exactly what you're looking for, but Control.Arrow has a rich
set of operators that can be used to combine functions.

For instance, there's an example on
http://en.wikibooks.org/wiki/Haskell/Understanding_arrows showing an addA
function that can be used to apply two functions to the same argument and
add the results:

Prelude import Control.Arrow
Prelude Control.Arrow let addA f g = f  g  arr (\ (y, z) - y + z)
Prelude Control.Arrow addA (+2) (*5) 10
62

If you're set on using the + and * operators, I'm guessing it's not
possible to define a (sane) instance of Num for (-), but it would probably
be instructive to try.



On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard 
christopher.how...@frigidcode.com wrote:

 Hi. I was just curious about something. In one of my math textbooks I see
 expressions like this

 f + g

 or

 (f + g)(a)

 where f and g are functions. What is meant is

 f(a) + g(a)

 Is there a way in Haskell you can make use of syntax like that (i.e.,
 expressions like f + g and f * g to create a new function), perhaps by
 loading a module or something?

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Bob Ippolito
Yes, you can do that, but you probably shouldn't.

See also:
http://www.haskell.org/haskellwiki/Num_instance_for_functions
http://hackage.haskell.org/package/applicative-numbers



On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard 
christopher.how...@frigidcode.com wrote:

 Hi. I was just curious about something. In one of my math textbooks I see
 expressions like this

 f + g

 or

 (f + g)(a)

 where f and g are functions. What is meant is

 f(a) + g(a)

 Is there a way in Haskell you can make use of syntax like that (i.e.,
 expressions like f + g and f * g to create a new function), perhaps by
 loading a module or something?

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Roman Cheplyaka
* Christopher Howard christopher.how...@frigidcode.com [2013-08-31 
21:01:38-0800]
 Hi. I was just curious about something. In one of my math textbooks I
 see expressions like this
 
 f + g
 
 or
 
 (f + g)(a)
 
 where f and g are functions. What is meant is
 
 f(a) + g(a)
 
 Is there a way in Haskell you can make use of syntax like that (i.e.,
 expressions like f + g and f * g to create a new function), perhaps
 by loading a module or something?

Not the syntax, but the notion itself corresponds exactly to idiom
brackets/applicative functors. In this case it's the Reader applicative.

Roman


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


Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Carter Schonwald
To clarify in Bobs remark : while you're still learning Haskell and the
type system , things like lifted Num on functions can lead to some
potentially confusing type errors.

That said, it's absolutely doable, and can be a very nice / powerful tool
when used appropriately.

On Sunday, September 1, 2013, Bob Ippolito wrote:

 Yes, you can do that, but you probably shouldn't.

 See also:
 http://www.haskell.org/haskellwiki/Num_instance_for_functions
 http://hackage.haskell.org/package/applicative-numbers



 On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard 
 christopher.how...@frigidcode.com javascript:_e({}, 'cvml',
 'christopher.how...@frigidcode.com'); wrote:

 Hi. I was just curious about something. In one of my math textbooks I see
 expressions like this

 f + g

 or

 (f + g)(a)

 where f and g are functions. What is meant is

 f(a) + g(a)

 Is there a way in Haskell you can make use of syntax like that (i.e.,
 expressions like f + g and f * g to create a new function), perhaps by
 loading a module or something?

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org javascript:_e({}, 'cvml',
 'Haskell-Cafe@haskell.org');
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe



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


Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Christopher Howard

On 08/31/2013 09:27 PM, Charlie Paul wrote:

I believe that this is what you want:
http://www.haskell.org/haskellwiki/Num_instance_for_functions

On Sat, Aug 31, 2013 at 10:01 PM, Christopher Howard
christopher.how...@frigidcode.com wrote:


The author seemed to be subtly mocking the idea. It seemed to be 
suggesting that a Num instance for functions would imply the need for 
constant number functions, which leads to difficulties. But I don't see 
why one would have to take it that far.


In any case, I just tried the NumInstances package from Hackage and it 
seems to work great.


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


Re: [Haskell-cafe] function arithmetic?

2013-09-01 Thread Richard A. O'Keefe

On 1/09/2013, at 7:06 PM, Christopher Howard wrote:
 It seemed to be suggesting that a Num instance for functions would imply the 
 need for constant number functions, which leads to difficulties. But I don't 
 see why one would have to take it that far.

You *cannot* make a type an instance of Num without saying how to
map integer literals to that type.  If you want (f+g)x = fx + gx
then having 2x = 2 makes perfect sense, because then (f+2)x = fx + 2
just as an APL or S programmer would expect.

The fact that 2(x+y) will then evaluate to 2 without evaluating x or y
is unfortunate, but inevitable.  I'm sure I could live with it.





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


[Haskell-cafe] function arithmetic?

2013-08-31 Thread Christopher Howard
Hi. I was just curious about something. In one of my math textbooks I 
see expressions like this


f + g

or

(f + g)(a)

where f and g are functions. What is meant is

f(a) + g(a)

Is there a way in Haskell you can make use of syntax like that (i.e., 
expressions like f + g and f * g to create a new function), perhaps by 
loading a module or something?


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