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

Data.Symbolic.TypedCode

Description

Template Haskell code is untyped, which is a bummer and leads to late error reporting. We make code expressions typed, at least for our particular domain.

Synopsis

Documentation

data Code a Source

The data type of a typed TH code experssion. The phantom parameter a is the type.

Instances

Eq (Code a) 
Floating a => Floating (Code a) 
Fractional a => Fractional (Code a) 
Num a => Num (Code a)

Lift Nums, Fractionals, and Floating to code expressions

Show (Code a) 

data Var a Source

type QCode a = Q (Code a)Source

reflectQC :: Q (Code a) -> Q ExpSource

This function is useful when splicing code expressions See DiffTest.hs for the examples of its use.

showQC :: Q (Code a) -> IO ()Source

op'add :: Num a => Code (a -> a -> a)Source

Typed primitive operations

op'sub :: Num a => Code (a -> a -> a)Source

op'mul :: Num a => Code (a -> a -> a)Source

op'div :: Fractional a => Code (a -> a -> a)Source

op'negate :: Num a => Code (a -> a)Source

op'recip :: Fractional a => Code (a -> a)Source

op'sin :: Floating a => Code (a -> a)Source

op'cos :: Floating a => Code (a -> a)Source

appC :: Code (a -> b) -> Code a -> Code bSource

Code expression combinators

integerC :: Num a => Integer -> Code aSource

Lifting from primitive datatypes to Code

new'diffVar :: Q (Var a)Source

A distinguished variable (over which we differentiate)

var'exp :: Var a -> Code aSource

Lift this variable to Code

reflectDF :: Var a -> Code a -> QCode (a -> a)Source

on'varC :: Var a -> Code b -> Maybe (Either (Var a) (Var b))Source

on'litC :: Code a -> Maybe (Code a)Source

Intensional code analysis Alas, TH.Exp is not a GADT. So, we have to do their emulation...

on'1opC :: Code (a -> b) -> Code d -> Maybe (Code a)Source

on'2opC :: Code (a -> b -> c) -> Code d -> Maybe (Code a, Code b)Source