Types as Macros - summer-school.racket-lang.org

Types as Macros - summer-school.racket-lang.org

Building Typed Languages with Turnstile Stephen Chang Racket Summer School 2018 (Thursday afternoon) Where are we in the schedule? Monday, Tuesday, Wednesday: Tools for building languages with Racket Thursday: How to build typed languages Thursday and Friday: We are still here But we are also here Lets look at some example languages built with Racket

The language of type rules is a language 1 2 1 2 A Macro-based Language in Racket UNTYPED-LANG #lang RACKET (provide-as [new-app #%app] [new- ]) (def-stx (new-app e1 e2) ; .... (#%app e1 e2)) (def-stx (new- x e) ; .... ( x e))

UNTYPED-PROG #lang UNTYPED-LANG ; uses: new-app, new- IDEA: A Typed Macro-based Language UNTYPED-LANG TYPED-LANG #lang RACKET (provide-as [new-app #%app] [new- ]) #lang RACKET (provide-as [typed-app #%app] [typed- ]) (def-stx (new-app e1 e2)

; .... (host-app e1 e2)) (def-stx (typed-app e1 e2) ; do typechecking (host-app e1 e2)) (def-stx (new- x e) ; .... (host- x e)) (def-stx (typed- [x : ] e) ; do typechecking (host- x e)) TYPED-PROG UNTYPED-PROG #lang UNTYPED-LANG

#lang TYPED-LANG ; uses: new-app, new- ; uses: typed-app, typed- do typechecking = expand + stx props (define-syntax (typed-app stx) (syntax-parse stx [(_ e1 e2) #:with e3 (local-expand #e1) #:with ( in ) (stx-prop #e3ty) #:with e4 (local-expand #e2) #:with arg (stx-prop #e4 ty) #:fail-unless (stx= #arg #in) (stx-prop #(#%app e3 e4) ty #)]))

Compute type Check type Assign type Types checked when macro expands Leverage Domain-specific Syntax [T-App] 1 2 1 2 Compute type Check type Assign type TURNSTILE: Type and Rewrite Rules

Conclusion: inputs (def-typed-stx (typed-app e e ) 1 [ e e e ( )] 1 2 e e e ] 2 [----------------------------- 1 2 1 1 1

2 2 in out in 1 2 [ e (#%app e1 e2) out]) Conclusion: outputs 2 TURNSTILE: Type and Rewrite Rules

(def-typed-stx (typed-app e1 e2) Expands to [ e e1 e1 ( in out)] [ e e2 e2 in] (def-typed-stx (typed-app e1 e2) -----------------------------(#%app e e2) ]) [ e e in )] out 1 e1 1 ( out [ e e2 e2 in] (def-stx (typed-app e1 e2) -----------------------------#:with e1 (expand e1) [ e (#%app e1 e2) out])

#:with ( in out) (detach e1) #:with e2 (expand e2) #:with arg (detach e2) #:fail-unless (stx= arg in) (attach (#%app e e ) ) Surface code Reader / Lexer / Parser AST (e.g., syntax objects) Expand and Type Check Checked, expanded AST Rest of compiler Core code / bytecode / machine code

Recently Viewed Presentations

  • MEAT COOKERY Prepared by: Dr. C. Boyd Ramsey

    MEAT COOKERY Prepared by: Dr. C. Boyd Ramsey

    dry heat cookery method for thick cuts LONG TIME, LOW TEMPERATURE COOKERY OF LARGE MEAT CUTS If a large meat cut, such as a prime rib or steamship round, is cooked for a long time at a low oven temperature...
  • Kalman filter, analog and wavelet postprocessing in the

    Kalman filter, analog and wavelet postprocessing in the

    UBC: Thomas Nipen, Roland Stull. OUTLINE. Ensemble and Kalman filtering (KF) to improve Numerical Weather and Air Quality Predictions. New methods based on KF and an analog approach (ANKF, AN) Tests of KF, ANKF, and AN to correct 10-m wind...
  • Multiuser Protection and the Mediator Pattern

    Multiuser Protection and the Mediator Pattern

    Multiuser Protection and the Mediator Pattern CSE432 02/22/2006 Matt Brenneke Multiuser Protection Follow Unix design, user and other Users must have a login name Basic authentication, user must provide login name and password User Object Restrictions Clients can't create User...
  • ANALYSIS OF FACTORS INFLUENCING THE USE OF HEART

    ANALYSIS OF FACTORS INFLUENCING THE USE OF HEART

    Therefore, it is difficult to compare directly the HRV of a subject during standing meditation and during sitting meditation. On the other hand, we did find that for those subjects who were in the sitting position throughout the experiment, their...
  • Surgery Quality and Workflow Manager

    Surgery Quality and Workflow Manager

    Surgery Verification Call. DISCUSS: The. Surgery Verification Call . is used by either a clerk or nurse to verify that the patient knows the correct time to arrive for surgery, has appropriate transportation arranged, where they are staying the night...
  • The Social Stratification of Fame Arnout van de

    The Social Stratification of Fame Arnout van de

    "Fame bubbles can burst as quickly as they formed" (Cowen 2000:15) "types who command media attention one day and are forgotten the next" (Rojek 2001:20-1) ... Jamie Foxx -- musician / actor / comedian talk radio host. Bill Murray --...
  • عرض تقديمي في PowerPoint

    عرض تقديمي في PowerPoint

    WDDM . الإصدار ‎1.0 أو ما هو أعلى. او. من خلال برنامج من مايكروسوفت يقوم بهذه المهمة عنك . وفي . الاخير والاهم ان يكون لديك طبعا قرص يحتوي على نسخة من النظام التشغيلي . windows7..
  • Reptiles - herpetology457.weebly.com

    Reptiles - herpetology457.weebly.com

    Rhynchocephalia(not in Iowa) Tuatara "spines on the back" 2 spp confined to New Zealand. Most active at night. Burrowing. Primarily insectivorous . Jaw teeth (acrodont)