In this message, we develop the `symbolic' differentiator for a subset of Haskell functions (which covers arithmetics and a bit of trigonometry). We can writeThe key here (as in most creative Haskell hacks) is the clever use of type classes, which may be the subject of my next post.
test1f x = x * x + fromInteger 1
test1 = test1f (2.0::Float)
test2f = diff_fn test1f
test2 = test2f (3.0::Float)
We can evaluate our functions _numerically_ -- and differentiate them _symbolically_.
[...]
We must point out that we specifically do _not_ represent our terms as algebraic datatypes. Our terms are regular Haskell terms, and can be compiled!
(The mail is from Oleg, who is the Haskell community's equivalent of _why: every few weeks or so he comes out with an absurd hack. The hackers mirrors the languages, as well: as _why's hacks are fast-and-loose and impenetrably obfuscated, Oleg's are often theory-heavy and impenetrably complicated.)