dispatch-union seems to work
This commit is contained in:
parent
74c707b65d
commit
dc11b3014e
|
@ -15,19 +15,19 @@
|
|||
|
||||
(provide dispatch-union)
|
||||
|
||||
(define-syntax/parse (dispatch-union ([type-to-replaceᵢ Aᵢ predicateᵢ] …)
|
||||
[X v result] …)
|
||||
(define-syntax/parse (dispatch-union v
|
||||
([type-to-replaceᵢ Aᵢ predicateᵢ] …)
|
||||
[Xⱼ result] …)
|
||||
((λ (x) (local-require racket/pretty) #;(pretty-write (syntax->datum x)) x)
|
||||
#`(cond
|
||||
. #,(stx-map
|
||||
(λ (X v result)
|
||||
(λ (X result)
|
||||
(syntax-parse X
|
||||
#:literals (tagged)
|
||||
[(tagged name [fieldᵢ (~optional :colon) typeᵢ] …)
|
||||
#`[((tagged? name fieldᵢ …) #,v) #,result]]
|
||||
[(tagged name [fieldₖ (~optional :colon) typeₖ] …)
|
||||
#`[((tagged? name fieldₖ …) v) #,result]]
|
||||
[other (raise-syntax-error 'graph
|
||||
"Unhandled union type"
|
||||
#'other)]))
|
||||
#'(X …)
|
||||
#'(v …)
|
||||
#'(Xⱼ …)
|
||||
#'(result …)))))
|
|
@ -28,14 +28,14 @@
|
|||
: (Values (U (tagged tg [a Symbol] [b Boolean])) Integer)
|
||||
(tagged tg [a 'abc] [b #f]) 1)
|
||||
|
||||
#;(check-equal?-values:
|
||||
(check-equal?-values:
|
||||
((f₃ string? string->symbol+acc) (tagged tg [a "abc"] [b #f]) 0)
|
||||
: (Values (U (tagged tg [a Symbol] [b Boolean])
|
||||
(tagged tg [a Boolean] [c Symbol]))
|
||||
Integer)
|
||||
(tagged tg [a 'abc] [b #f]) 1)
|
||||
|
||||
#;(check-equal?-values:
|
||||
(check-equal?-values:
|
||||
((f₃ string? string->symbol+acc) (tagged tg [a #t] [c "def"]) 0)
|
||||
: (Values (U (tagged tg [a Symbol] [b Boolean])
|
||||
(tagged tg [a Boolean] [c Symbol]))
|
||||
|
|
|
@ -255,10 +255,9 @@ way up, so that a simple identity function can be applied in these cases.
|
|||
(U (_txⱼ _Tᵢ …) …)
|
||||
|
||||
#:using
|
||||
(dispatch-union ([type-to-replaceᵢ Aᵢ predicateᵢ]
|
||||
…)
|
||||
[_Xⱼ v ((_fxⱼ . _args) v acc)]
|
||||
…)
|
||||
(dispatch-union v
|
||||
([type-to-replaceᵢ Aᵢ predicateᵢ] …)
|
||||
[_Xⱼ ((_fxⱼ . _args) v acc)] …)
|
||||
|
||||
#:with-defintitions
|
||||
(define-fold _fxⱼ _txⱼ _Xⱼ type-to-replaceᵢ …)
|
||||
|
|
Loading…
Reference in New Issue
Block a user