
On 2 okt 2009, at 20:37, Jake McArthur wrote:
Günther Schmidt wrote:
And that I find to be the really tricky part, how do I *design* a DSL?
I once wrote a tutorial on this subject in which I explain that designing a DSL is not so much different from an ordinary programming language; the only difference is that you do not have to think about type systems and abstraction mechanisms. The tutorial can be found in: @inproceedings{SwieAzSar98Braga, Author = {Swierstra, S. Doaitse and Azero~Alcocer, Pablo R. and Saraiva, Jo{\~a}o A.}, Booktitle = {Advanced Functional Programming, Third International School, AFP'98}, Date-Added = {2008-07-15 17:22:15 +0200}, Date-Modified = {2009-01-16 17:35:05 +0100}, Editor = {Swierstra, S. D. and Henriques, Pedro and Oliveira, Jos \'{e}}, Pages = {150-206}, Publisher = {Springer-Verlag}, Series = {LNCS}, Title = {Designing and Implementing Combinator Languages}, Volume = {1608}, Year = {1999}} It basically describes the origins of the Utrecht Attribute Grammar System, uuagc, available from hackage; the basic message is that when you implement a language you use compiler construction tools! An example of this can be found in a paper Olaf Chitil and I recently published in the JFP: @article{CambridgeJournals:2837460, Author = {SWIERSTRA, S. DOAITSE and CHITIL, OLAF}, Date-Added = {2009-02-13 10:17:23 +0100}, Date-Modified = {2009-02-13 10:17:23 +0100}, Doi = {10.1017/S0956796808006990}, Eprint = {http://journals.cambridge.org/article_S0956796808006990}, Journal = {Journal of Functional Programming}, Number = {01}, Pages = {1-16}, Title = {Linear, bounded, functional pretty-printing}, Url = {http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=2837460&fulltextType=RC&fileId=S0956796808006990 }, Volume = {19}, Year = {2009}, Abstract = { ABSTRACT We present two implementations of Oppen's pretty-printing algorithm in Haskell that meet the efficiency of Oppen's imperative solution but have a simpler and a clear structure. We start with an implementation that uses lazy evaluation to simulate two co-operating processes. Then we present an implementation that uses higher-order functions for delimited continuations to simulate co- routines with explicit scheduling. }, Bdsk-Url-1 = {http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=2837460&fulltextType=RC&fileId=S0956796808006990 }, Bdsk-Url-2 = {http://dx.doi.org/10.1017/S0956796808006990}} This paper describes two implementation of a functional pretty printing, finally solving the problem how to do so with limited alook- ahead, as in Oppen's orginal paper. One of the solutions was created using an attribute grammar way of thinking and the attribute grammar can be found at the end of the technical report, and I hope that this example convinces you of the elegance of this approach: @techreport{PPTr2004, Author = {Swierstra, S.D.}, Date-Added = {2009-01-04 17:21:54 +0100}, Date-Modified = {2009-01-04 17:21:54 +0100}, Institution = {Inst. of Information and Comp. Science, Utrecht Univ.}, Note = {submitted for publication}, Number = {UU-CS-2004-025a}, Pubcat = {techreport}, Title = {Linear, Online, Functional Pretty printing (extended and corrected version)}, Urlpdf = {{http://archive.cs.uu.nl/pub/RUU/CS/techreps/CS-2004/2004-025a.pdf }}, Year = 2004} In a more abstract setting your question is also "How do I design a library", "How do I design a consistent theory", and "How do I model something". These questions are harder to answer ;-} Doaitse Swierstra