Currying
(define (mogrify g f)
(lambda (x) (g f x)))
(define (fderiv2 f) (mogrify deriv f))
(plot (function (fsub (fderiv2 sin) cos) -2pi 2pi))
- In the spirit of the discussion above, the argument
f
tomogrify
is kind of useless. We can hide it inside a new combinator:
(define (currify g)
(lambda (f) (lambda (x) (g f x))))
(define fderiv3 (currify deriv))
(module+ test
(for ([x test-points])
(check-= (cos x) ((fderiv3 sin) x) epsilon)))
The combinator
currify
is common enough to be built into the racket library under the name curryYou can verify that
curry
is a drop replacement for the functioncurrify
; if you read the documentation you can see that it's actually more general.for whatever reason
curry
is not built into plait, but our definition ifcurrify
should work fine there.