
Hi, sdiyazg@sjtu.edu.cn wrote:
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
One approach to achieve this is to define your own version of +, using the equation in the last comment of the above code snippet: (g .+. h) t = g t + h t Now you can write the following: f = g .+. h You could now implement .*., ./. and so on. (I use the dots in the operator names because the operator is applied pointwise). The implementations would look like this: (g .+. h) t = g t + h t (g .*. h) t = g t * h t (g ./. h) t = g t / h t This is a bit more low-tech than the proposals in the other answers, but might be good enough for some applications. Tillmann