3
我试图定义一个多态类型:如何解决这个柯里函数中的类型不匹配错误?
(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
我感到困惑的是, 我做错了什么?
非常感谢,我明白了。 – izuo