liboleg-2010.1.10.0: An evolving collection of Oleg Kiselyov's Haskell modules



Reify the (compiled) code to its typed TH representation (or, the dictionary *view*, to be precise) and reflect/compile that code. We must spread the code through several modules, due to the particular requirement of the Template Haskell. See DiffTest.hs for reflection of the differentiated TH code back into (machine) code.



testf1 :: Num a => aSource

diffC :: (Floating a, Floating b) => Var b -> Code a -> Code aSource

We can define a function

we can even compile it. At any point, we can reify it, into a `dictionary view' The result is the TH code, which we can print, and compile back to the code. We can also differentiate the TH code, simplify it, partially evaluate it, etc.

Symbolic Differentiation of the reified, typed TH code expressions The derivative over the code is a type preserving operation

simpleC :: Floating a => Var b -> Code a -> Code aSource

Simplification rules simplification is type-preserving obviously, simplification is an `open-ended' problem: we could even recognize common sub-expressions and simplify them by introducing let binding. In the following however, we do trivial simplification only. One can always add more simplification rules later.

simpleCL :: Floating a => Var b -> Code a -> Maybe (Code a)Source

repeat until no simplifications are made

diff_fn :: Floating b => (forall a. Floating a => a -> a) -> QCode (b -> b)Source

And that's about it. Putting it all together gives us:

show_fn :: (forall a. Floating a => a -> a) -> IO ()Source

This is a useful helper to show us the code of the function in question