From: admin Date: Fri, 22 Sep 2023 04:20:35 +0000 (+0900) Subject: Implement typed curried definitions X-Git-Tag: v0.1.0~10 X-Git-Url: https://git.vouivredigital.com/?a=commitdiff_plain;h=f4ec208cd66a31711626039f644f20d592bcc8ca;p=vouivre.git Implement typed curried definitions --- diff --git a/curry.scm b/curry.scm index 77489c4..33fb629 100644 --- a/curry.scm +++ b/curry.scm @@ -16,6 +16,7 @@ expand parse symtab + type-of ∷)) (define symtab '()) @@ -257,6 +258,28 @@ `(lambda (,var) ,bodye))))) (('letrecc1 ((? symbol? name) expr) body) (type-error 0 'letrecc1 name expr body)) + (('definec (? (lambda (x) + (and + (pair? x) + (symbol? (car x)) + (var-list? (cdr x)))) + (name vars ..1)) + body) + (expand + symtab + `(definec ,name + ,(fold-right (lambda (x prev) + `(λc ,x ,prev)) + body vars)))) + (('definec (? symbol? name) body) + (let ((t e (expand symtab body))) + (if (not t) + (type-error 5 "in body of" `(definec ,name ,body)) + (begin + (∷% name t) + (values + #f + `(define ,name ,e)))))) ((f) (let ((t e (expand symtab f))) (values @@ -386,3 +409,6 @@ (define-syntax-rule (∷ name type) (∷% 'name (parse 'type))) + +(define (type-of x) + (pt (assoc-ref symtab x)))