From 8978b504678dfd1f979259681b82bf5a611f69f2 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 4 Feb 2023 21:34:06 -0500 Subject: Emitting overloaded functions seems to work! --- chickadee/graphics/seagull.scm | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'chickadee/graphics') diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm index 6b8073d..dcddfb9 100644 --- a/chickadee/graphics/seagull.scm +++ b/chickadee/graphics/seagull.scm @@ -1956,6 +1956,17 @@ ;; of non-quantified function type specifications, one for each unique ;; type of call in the program. +;; Check if the substitutions in a and b do not contain +;; contradictions. +(define (consistent? a b) + (every (match-lambda + ((from . to) + (let ((other (assq-ref b from))) + (or (not other) (equal? to other))))) + a)) + +;; Compute all the valid permutations of substitutions that a +;; predicate could produce. (define (possible-substitutions pred) (match pred (#t '()) @@ -1974,17 +1985,12 @@ (append-map (lambda (a) (if (null? rest-options) (list a) - (map (lambda (b) - (compose-substitutions a b)) - rest-options))) + (filter-map (lambda (b) + (and (consistent? a b) + (compose-substitutions a b))) + rest-options))) options))))))) -(define (possible-signatures type) - (define type* (for-all-type-ref type)) - (map (lambda (subs) - (apply-substitutions-to-type type* subs)) - (possible-substitutions (for-all-type-predicate type)))) - (define (resolve-overloads program) (match program (('t types ('top-level bindings body)) -- cgit v1.2.3