instance (Num a, Eq a) => Num (x -> a) where
fromInteger = const . fromInteger
f + g = liftM2 (+) f g
f * g = liftM2 (*) f g
f - g = liftM2 (-) f g
negate = (negate .)
abs = (abs .)
signum = (signum .)
Fun fact: in the J programming language, (f g) = x f (g y) if f is a binary operator and g is a unary one.
f =. +|
_10 f _20
Name:
Anonymous2012-09-23 14:58
>>7 http://wiki.nars2000.org/index.php/Trains
It's the same way in NARS2000 Extended APL (which adopted them from J). f←(+|)
¯10 f ¯20
It can also be written with the ∘ operator. f←+∘|
¯10 f ¯20
Name:
Anonymous2012-09-23 15:05
>>1,2
APL arithmetic functions also return the identity element when given an empty vector. +/⍳0
0
-/⍳0
0
×/⍳0
1
÷/⍳0
1
*/⍳0
1