macrotypes/tapl/stlc+box.rkt
Stephen Chang bf126449b4 define-type-constructor supports annotated bound vars
- use this to impl forall in fomega
- define-type-constructor default arity is =1
- define explicit normalize fn in fomega -- speeds up tests 15%
- move same-type to define-syntax-category
2015-10-09 16:59:48 -04:00

27 lines
655 B
Racket

#lang s-exp "typecheck.rkt"
(extends "stlc+cons.rkt")
;; Simply-Typed Lambda Calculus, plus mutable references
;; Types:
;; - types from stlc+cons.rkt
;; - Ref constructor
;; Terms:
;; - terms from stlc+cons.rkt
;; - ref deref :=
(define-type-constructor Ref)
(define-typed-syntax ref
[(_ e)
#:with (e- τ) (infer+erase #'e)
( (box e-) : (Ref τ))])
(define-typed-syntax deref
[(_ e)
#:with (e- (τ)) ( e as Ref)
( (unbox e-) : τ)])
(define-typed-syntax :=
[(_ e_ref e)
#:with (e_ref- (τ1)) ( e_ref as Ref)
#:with (e- τ2) (infer+erase #'e)
#:when (typecheck? #'τ1 #'τ2)
( (set-box! e_ref- e-) : Unit)])