【发布时间】:2016-08-09 06:53:45
【问题描述】:
我试图定义一个多态类型:
(define-type (listt a)
(U Empty
(Cons a)))
(struct Empty ())
(struct (a) Cons ([v : a] [w : (listt a)]))
还有一个柯里化函数:
;; a better name for subst-c is subst-currying
(: subst-c : (∀ (a) ((-> a Boolean) -> a (listt a) -> (listt a))))
(define (subst-c pred)
(lambda (n listt)
(match listt
[(Empty)
(Empty)]
[(Cons e t)
(if (pred e)
(Cons n ((subst-c pred) n t))
(Cons e ((subst-c pred) n t)))])))
但出现错误
;Type Checker: type mismatch
; expected: Nothing
; given: a
; in: n
;Type Checker: type mismatch
; expected: (U Empty (Cons Nothing))
; given: (U Empty (Cons a))
; in: t
我很困惑,我做错了什么?
【问题讨论】:
标签: racket typed-racket