[Haskell-cafe] Safe forward-mode AD in Haskell?

Björn Buckwalter bjorn.buckwalter at gmail.com
Wed May 9 10:32:51 EDT 2007


> > d :: Num a => (forall b. (Num b) => (a -> b) -> b -> b) -> a -> a
> > d f x = let (Bundle y y') = f lift (Bundle x 1) in y'
>
> The key change is in the type of d, which now accepts a polymorphic
> function on numbers, but passes in a "lift" function, which allows us to
> pass in higher-level variables.  In one sense this function is ugly.  In
> another sense, it's prettier, as you can now hide *all* of the Bundle data
> in a "differentiation" module.

To summarize:

In my original version it is necessary to export 'd' and 'lift', which
both expose 'Bundle' through their type signatures (and 'lift' even
returns a 'Bundle', though how one could (ab)use it outside the
intended context of a 'd' escapes me).

In constrast, with your variation only 'd' need be exported and
everything else in the module (including 'Bundle) is completely
hidden. The cost is that functions must be "conditioned" before they
can be differentiated.

Thanks for your input!

-Bjorn


More information about the Haskell-Cafe mailing list