NB XXX: Renamed reflection API functions

The names of reflection API functions were previously confusing.
They included weird patterns that only made sense inside the Cur
implementation.
As they are Racket functions, they ought to somehow indicate that these
functions are for Cur, which they did not.
This commit is contained in:
William J. Bowman 2016-03-14 17:20:58 -04:00
parent 8b3159bb6f
commit 4f272dc507
No known key found for this signature in database
GPG Key ID: DDD48D26958F0D1A
9 changed files with 44 additions and 44 deletions

View File

@ -30,52 +30,52 @@ phase 1 in Cur.}
] ]
} }
@defproc[(type-infer/syn [syn syntax?]) @defproc[(cur-type-infer [syn syntax?])
(or/c syntax? #f)]{ (or/c syntax? #f)]{
Returns the type of the Cur term @racket[syn], or @racket[#f] if no type could be inferred. Returns the type of the Cur term @racket[syn], or @racket[#f] if no type could be inferred.
@examples[ @examples[
(eval:alts (type-infer/syn #'(λ (x : Type) x)) (eval:alts (cur-type-infer #'(λ (x : Type) x))
(eval:result @racket[#'(Π (x : (Type 0)) (Type 0))] "" "")) (eval:result @racket[#'(Π (x : (Type 0)) (Type 0))] "" ""))
(eval:alts (type-infer/syn #'Type) (eval:alts (cur-type-infer #'Type)
(eval:result @racket[#'(Type 1)] "" "")) (eval:result @racket[#'(Type 1)] "" ""))
] ]
} }
@defproc[(type-check/syn? [syn syntax?]) @defproc[(cur-type-check? [syn syntax?])
boolean?]{ boolean?]{
Returns @racket[#t] if the Cur term @racket[syn] is well-typed, or @racket[#f] otherwise. Returns @racket[#t] if the Cur term @racket[syn] is well-typed, or @racket[#f] otherwise.
@examples[ @examples[
(eval:alts (type-check/syn? #'(λ (x : Type) x)) (eval:alts (cur-type-check? #'(λ (x : Type) x))
(eval:result @racket[#t] "" "")) (eval:result @racket[#t] "" ""))
(eval:alts (type-check/syn? #'Type) (eval:alts (cur-type-check? #'Type)
(eval:result @racket[#t] "" "")) (eval:result @racket[#t] "" ""))
(eval:alts (type-check/syn? #'x) (eval:alts (cur-type-check? #'x)
(eval:result @racket[#f] "" "")) (eval:result @racket[#f] "" ""))
] ]
} }
@defproc[(normalize/syn [syn syntax?]) @defproc[(cur-normalize [syn syntax?])
syntax?]{ syntax?]{
Runs the Cur term @racket[syn] to a value. Runs the Cur term @racket[syn] to a value.
@examples[ @examples[
(eval:alts (normalize/syn #'((λ (x : Type) x) Bool)) (eval:alts (cur-normalize #'((λ (x : Type) x) Bool))
(eval:result @racket[#'Bool] "" "")) (eval:result @racket[#'Bool] "" ""))
(eval:alts (normalize/syn #'(sub1 (s (s z)))) (eval:alts (cur-normalize #'(sub1 (s (s z))))
(eval:result @racket[#'(s z)] "" "")) (eval:result @racket[#'(s z)] "" ""))
] ]
} }
@defproc[(step/syn [syn syntax?]) @defproc[(cur-step [syn syntax?])
syntax?]{ syntax?]{
Runs the Cur term @racket[syn] for one step. Runs the Cur term @racket[syn] for one step.
@examples[ @examples[
(eval:alts (step/syn #'((λ (x : Type) x) Bool)) (eval:alts (cur-step #'((λ (x : Type) x) Bool))
(eval:result @racket[#'Bool] "" "")) (eval:result @racket[#'Bool] "" ""))
(eval:alts (step/syn #'(sub1 (s (s z)))) (eval:alts (cur-step #'(sub1 (s (s z))))
(eval:result @racket[#'(((((elim Nat (Type 0)) (eval:result @racket[#'(((((elim Nat (Type 0))
(λ (x2 : Nat) Nat)) z) (λ (x2 : Nat) Nat)) z)
(λ (x2 : Nat) (λ (ih-n2 : Nat) x2))) (λ (x2 : Nat) (λ (ih-n2 : Nat) x2)))

View File

@ -169,7 +169,7 @@ Check that expression @racket[e] has type @racket[type], causing a type-error if
} }
@defform[(run syn)]{ @defform[(run syn)]{
Like @racket[normalize/syn], but is a syntactic form to be used in surface syntax. Like @racket[cur-normalize], but is a syntactic form to be used in surface syntax.
Allows a Cur term to be written by computing part of the term from Allows a Cur term to be written by computing part of the term from
another Cur term. another Cur term.
@ -179,7 +179,7 @@ another Cur term.
} }
@defform[(step syn)]{ @defform[(step syn)]{
Like @racket[run], but uses @racket[step/syn] to evaluate only one step and prints intermediate Like @racket[run], but uses @racket[cur-step] to evaluate only one step and prints intermediate
results before returning the result of evaluation. results before returning the result of evaluation.
@examples[#:eval curnel-eval @examples[#:eval curnel-eval

View File

@ -60,10 +60,10 @@
(all-from-out racket/syntax) (all-from-out racket/syntax)
cur->datum cur->datum
cur-expand cur-expand
type-infer/syn cur-type-infer
type-check/syn? cur-type-check?
normalize/syn cur-normalize
step/syn cur-step
cur-equal?)) cur-equal?))
(begin-for-syntax (begin-for-syntax
@ -224,12 +224,12 @@
;; Reflection tools ;; Reflection tools
(define (normalize/syn syn) (define (cur-normalize syn)
(datum->cur (datum->cur
syn syn
(eval-cur syn))) (eval-cur syn)))
(define (step/syn syn) (define (cur-step syn)
(datum->cur (datum->cur
syn syn
(term (step ,(delta) ,(subst-bindings (cur->datum syn)))))) (term (step ,(delta) ,(subst-bindings (cur->datum syn))))))
@ -239,14 +239,14 @@
(and (judgment-holds (equivalent ,(delta) ,(eval-cur e1) ,(eval-cur e2))) #t)) (and (judgment-holds (equivalent ,(delta) ,(eval-cur e1) ,(eval-cur e2))) #t))
;; TODO: Document local-env ;; TODO: Document local-env
(define (type-infer/syn syn #:local-env [env '()]) (define (cur-type-infer syn #:local-env [env '()])
(parameterize ([gamma (for/fold ([gamma (gamma)]) (parameterize ([gamma (for/fold ([gamma (gamma)])
([(x t) (in-dict env)]) ([(x t) (in-dict env)])
(extend-Γ/syn (thunk gamma) x t))]) (extend-Γ/syn (thunk gamma) x t))])
(let ([t (type-infer/term (eval-cur syn))]) (let ([t (type-infer/term (eval-cur syn))])
(and t (datum->cur syn t))))) (and t (datum->cur syn t)))))
(define (type-check/syn? syn type) (define (cur-type-check? syn type)
(type-check/term? (eval-cur syn) (eval-cur type))) (type-check/term? (eval-cur syn) (eval-cur type)))
;; Takes a Cur term syn and an arbitrary number of identifiers ls. The cur term is ;; Takes a Cur term syn and an arbitrary number of identifiers ls. The cur term is

View File

@ -32,7 +32,7 @@
(coq-defns (format "~a~a~n" (coq-defns) str))) (coq-defns (format "~a~a~n" (coq-defns) str)))
(define (constructor-args syn) (define (constructor-args syn)
(syntax-parse (type-infer/syn syn) (syntax-parse (cur-type-infer syn)
#:datum-literals (Π :) #:datum-literals (Π :)
[(Π (x:id : t) body) [(Π (x:id : t) body)
(cons #'x (constructor-args #'body))] (cons #'x (constructor-args #'body))]

View File

@ -9,5 +9,5 @@
(define-syntax (some/i syn) (define-syntax (some/i syn)
(syntax-case syn () (syntax-case syn ()
[(_ a) [(_ a)
(let ([a-ty (type-infer/syn #'a)]) (let ([a-ty (cur-type-infer #'a)])
#`(some #,a-ty a))])) #`(some #,a-ty a))]))

View File

@ -31,8 +31,8 @@
(define-syntax (conj/i syn) (define-syntax (conj/i syn)
(syntax-case syn () (syntax-case syn ()
[(_ a b) [(_ a b)
(let ([a-type (type-infer/syn #'a)] (let ([a-type (cur-type-infer #'a)]
[b-type (type-infer/syn #'b)]) [b-type (cur-type-infer #'b)])
#`(conj #,a-type #,b-type a b))])) #`(conj #,a-type #,b-type a b))]))
(define thm:and-is-symmetric (define thm:and-is-symmetric

View File

@ -162,7 +162,7 @@
#:attr types #:attr types
;; TODO: Detect failure, report error/suggestions ;; TODO: Detect failure, report error/suggestions
(for/list ([e (attribute indices)]) (for/list ([e (attribute indices)])
(or (type-infer/syn e) (or (cur-type-infer e)
(raise-syntax-error (raise-syntax-error
'match 'match
(format (format
@ -183,7 +183,7 @@
(lambda (return) (lambda (return)
;; NB: unhygenic ;; NB: unhygenic
;; Normalize at compile-time, for efficiency at run-time ;; Normalize at compile-time, for efficiency at run-time
(normalize/syn (cur-normalize
#`((lambda #`((lambda
;; TODO: utteraly fragile; relines on the indices being referred to by name, not computed ;; TODO: utteraly fragile; relines on the indices being referred to by name, not computed
;; works only for simple type familes and simply matches on them ;; works only for simple type familes and simply matches on them
@ -244,7 +244,7 @@
(define/syntax-parse type:inductive-type-declaration (cur-expand type-syn)) (define/syntax-parse type:inductive-type-declaration (cur-expand type-syn))
(let ([ih-name (quasisyntax/loc src #,(format-id name-syn "ih-~a" name-syn))] (let ([ih-name (quasisyntax/loc src #,(format-id name-syn "ih-~a" name-syn))]
;; Normalize at compile-time, for efficiency at run-time ;; Normalize at compile-time, for efficiency at run-time
[ih-type (normalize/syn #`(#,motive #,@(attribute type.indices) #,name-syn))]) [ih-type (cur-normalize #`(#,motive #,@(attribute type.indices) #,name-syn))])
(dict-set! ih-dict (syntax->datum name-syn) ih-name) (dict-set! ih-dict (syntax->datum name-syn) ih-name)
(append decls (list #`(#,ih-name : #,ih-type))))))) (append decls (list #`(#,ih-name : #,ih-type)))))))
@ -256,7 +256,7 @@
(or maybe-return-type (or maybe-return-type
;; Ignore errors when trying to infer this type; other attempt might succeed ;; Ignore errors when trying to infer this type; other attempt might succeed
(with-handlers ([values (lambda _ #f)]) (with-handlers ([values (lambda _ #f)])
(type-infer/syn #:local-env (attribute p.local-env) #'b))))) (cur-type-infer #:local-env (attribute p.local-env) #'b)))))
(define-syntax-class (match-clause D motive) (define-syntax-class (match-clause D motive)
(pattern (pattern
@ -292,7 +292,7 @@
(~optional (~optional
(~seq #:in ~! t) (~seq #:in ~! t)
#:defaults #:defaults
([t (or (type-infer/syn #'d) ([t (or (cur-type-infer #'d)
(raise-syntax-error (raise-syntax-error
'match 'match
"Could not infer discrimnant's type. Try using #:in to declare it." "Could not infer discrimnant's type. Try using #:in to declare it."
@ -318,7 +318,7 @@
(elim (elim
D.inductive-name D.inductive-name
#,(or #,(or
(type-infer/syn (attribute return-type)) (cur-type-infer (attribute return-type))
(raise-syntax-error (raise-syntax-error
'match 'match
"Could not infer type of motive. Sorry, you'll have to use elim." "Could not infer type of motive. Sorry, you'll have to use elim."
@ -337,14 +337,14 @@
#:attr type (cond #:attr type (cond
[(attribute t) [(attribute t)
;; TODO: Code duplication in :: ;; TODO: Code duplication in ::
(unless (type-check/syn? #'e #'t) (unless (cur-type-check? #'e #'t)
(raise-syntax-error (raise-syntax-error
'let 'let
(format "Term ~a does not have expected type ~a. Inferred type was ~a" (format "Term ~a does not have expected type ~a. Inferred type was ~a"
(cur->datum #'e) (cur->datum #'t) (cur->datum (type-infer/syn #'e))) (cur->datum #'e) (cur->datum #'t) (cur->datum (cur-type-infer #'e)))
#'e (quasisyntax/loc #'x (x e)))) #'e (quasisyntax/loc #'x (x e))))
#'t] #'t]
[(type-infer/syn #'e)] [(cur-type-infer #'e)]
[else [else
(raise-syntax-error (raise-syntax-error
'let 'let
@ -362,22 +362,22 @@
[(_ pf t) [(_ pf t)
(begin (begin
;; TODO: Code duplication in let-clause pattern ;; TODO: Code duplication in let-clause pattern
(unless (type-check/syn? #'pf #'t) (unless (cur-type-check? #'pf #'t)
(raise-syntax-error (raise-syntax-error
':: '::
(format "Term ~a does not have expected type ~a. Inferred type was ~a" (format "Term ~a does not have expected type ~a. Inferred type was ~a"
(cur->datum #'pf) (cur->datum #'t) (cur->datum (type-infer/syn #'pf))) (cur->datum #'pf) (cur->datum #'t) (cur->datum (cur-type-infer #'pf)))
syn)) syn))
#'(void))])) #'(void))]))
(define-syntax (run syn) (define-syntax (run syn)
(syntax-case syn () (syntax-case syn ()
[(_ expr) (normalize/syn #'expr)])) [(_ expr) (cur-normalize #'expr)]))
(define-syntax (step syn) (define-syntax (step syn)
(syntax-case syn () (syntax-case syn ()
[(_ expr) [(_ expr)
(let ([t (step/syn #'expr)]) (let ([t (cur-step #'expr)])
(displayln (cur->datum t)) (displayln (cur->datum t))
t)])) t)]))
@ -393,6 +393,6 @@
(syntax-case syn () (syntax-case syn ()
[(_ term) [(_ term)
(begin (begin
(printf "\"~a\" has type \"~a\"~n" (syntax->datum #'term) (syntax->datum (type-infer/syn #'term))) (printf "\"~a\" has type \"~a\"~n" (syntax->datum #'term) (syntax->datum (cur-type-infer #'term)))
;; Void is undocumented and a hack, but sort of works ;; Void is undocumented and a hack, but sort of works
#'(void))])) #'(void))]))

View File

@ -220,7 +220,7 @@
[pf (proof-state-proof ps)]) [pf (proof-state-proof ps)])
(unless (proof-state-proof-complete? ps) (unless (proof-state-proof-complete? ps)
(raise-syntax-error 'qed "Proof contains holes" (pf (current-hole-pretty-symbol)))) (raise-syntax-error 'qed "Proof contains holes" (pf (current-hole-pretty-symbol))))
(unless (type-check/syn? pf t) (unless (cur-type-check? pf t)
(raise-syntax-error 'qed "Invalid proof" pf t)) (raise-syntax-error 'qed "Invalid proof" pf t))
pf))) pf)))

View File

@ -38,7 +38,7 @@
#`(define-syntax (#,name syn) #`(define-syntax (#,name syn)
(syntax-case syn () (syntax-case syn ()
[(_ arg args (... ...)) [(_ arg args (... ...))
#`(#,(format-id syn "~a-~a" '#,name (type-infer/syn #'arg)) #`(#,(format-id syn "~a-~a" '#,name (cur-type-infer #'arg))
arg arg
args (... ...))]))))])) args (... ...))]))))]))
@ -57,7 +57,7 @@
#`(begin #`(begin
#,@(for/list ([def (syntax->list #'(defs ...))]) #,@(for/list ([def (syntax->list #'(defs ...))])
(let-values ([(name body) (process-def def)]) (let-values ([(name body) (process-def def)])
(unless (type-check/syn? (unless (cur-type-check?
body body
#`(#,(dict-ref #`(#,(dict-ref
(dict-ref typeclasses (syntax->datum #'class)) (dict-ref typeclasses (syntax->datum #'class))