Template Haskell for EDSLsApplication to Embedded Domain Specific LanguagesI am interested in the application of meta-programming to the development of Embedded Domain Specific Languages. Specifically I am interested in its applications in the following areas.OptimisationCompilers can only reason about and optimise over structures that they are familiar with. When a user writes a module they may define functions which conform (provably) to various algebraic laws. Meta-programming can be used to write optimisation passes that understand the relationship between user defined functions and transform them. As an example consider the image overlay function from Pan. type Colour = (Double, Double, Double, Double) type Point = (Double, Double) type Image a = Point -> a cOver :: Colour -> Colour -> Colour cOver (r1,g1,b1,a1) (r2,g2,b2,a2) = (h r1 r2, h g1 g2, h b1 b2, h a1 a2) where h x1 x2 = x1 + (1 - a1) * x2 lift2 :: (a -> a -> a) -> (p -> a) -> (p -> a) -> (p -> a) lift2 h f1 f2 = \p -> h (f1 p) (f2 p) over :: Image Colour -> Image Colour -> Image Colour over = lift2 cOver invisible :: Image Colour invisible (x,y) = (0,0,0,0) Now consider the expression invisible `over` im We can prove that this is the same as im (exercise for the reader). But this is not something that the compiler knows or even feasibly could know. Given a compiler one can always think of more optimisations it could do. (There are theorems which prove this to be the case.) Yet with Template Haskell transforming such an expression is entirely feasible. Semantic extensionTemplate Haskell can also be used for slightly uglier purposes. It should be possible to change the semantics of the language by performing certain transformations. For instance, one could probably add assignment to the language without too much effort. Nonetheless, semantic extension may be something that programmers will find useful.Tool supportIt should be possible using Template Haskell to provide a user with domain specific error messages and perhaps even specialized profiling information. (The latter may require some more changes to Template Haskell.) If we are to really convince users of EDSLs that they are programming in another language, provision of such tool support will be necessary.More general meta-programing considerationsMy current research focuses upon these issues and also more general meta-programming issues such as:
|
| Last modified: Thu Jun 19 22:14:44 EST 2003 |