[Haskell-cafe] Are there arithmetic composition of functions?

sdiyazg at sjtu.edu.cn sdiyazg at sjtu.edu.cn
Mon Mar 19 17:57:30 CET 2012


By arithmetic I mean the everyday arithmetic operations used in engineering. 
In signal processing for example, we write a lot of expressions like f(t)=g(t)+h(t)+g'(t) or f(t)=g(t)*h(t).
I feel it would be very natural to have in haskell something like
   g::Float->Float
   --define g here
   h::Float->Float
   --define h here
   f::Float->Float
   f = g+h --instead of f t = g t+h t
   --Of course, f = g+h is defined as f t = g t+h t
I guess as long as all operands have the same number of arrows in there types then they should have the potential to be composed like this.
Or
   g::Float->Float->Float
   --define g here
   h::Float->Float->Float
   --define h here
   f::Float->Float->Float
   f = g+h --means f x y = g x y + h x y
   -- f = g+h is defined as f x = g x+h x which in turn is defined as f x y = g x y+h x y
This should be easy to implement, with TH perhaps. And I thought there would be a library (not in the language itself, of course) for this, but I haven't find one. Can someone tell me whether there is some implementation of such composition? If there isn't then I may build one.



More information about the Haskell-Cafe mailing list