-
78
pages
-
English
-
Documents
Description
Multi-stage Programming inMetaOCamlWalid TahaRice UniversityGenerative Programming and Component Engineering (GPCE 2004) TutorialCopyright is held by the author. OOPSLA'04, October 24-28, 2004, Vancouver, British Columbia, Canada. 2004 ACM 04/0010.Why Multi-stage Programming?Reasons are purely economic:• Problem 1: Abstraction mechanisms (functions, objects, classes…) have runtime cost– Result 1: You don’t use them– Result 2: That costs you programmer productivity• Idea: Use generative programming (GPCE)• Problem 2: Writing good generative programs is hard23332322Why program generation is hard• First, there is the issue of hygiene (as in macros)• More generally, what can we statically guarantee about what’s generated? • Important: “Statically” = by looking at the generator?Syntactic Type Build Combinecorrectness? correctness?Approach“f (x,y)” F XReject “f (x,)” Reject “7 (8)”StringDatatype23333332323Multi-stage programming (MSP)• Provide abstraction mechanisms like: polymorphism, higher-order functions, exceptions, …• Provide constructs that allow “generation”• Without damaging the static typing disciplineSyntactic Type Build Combinecorrectness? correctness?Approach“f (x,y)” F XReject “f (x,)” Reject “7 (8)”StringDatatype…MSPMulti-stage programming (MSP)Three staging annotations:Construct Example Resulta=<2*4>a = <2*4>Brackets:b=<9+2*4>b = <9+~a>Escape:c=17c = !bRun:Typing rules ...
-
Publié par
-
Langue
English