我试图为从另一个结构继承的结构定义合约。
#lang racket
(require racket/contract racket/contract/parametric)
(struct semigroup (op))
(struct monoid (mempty) #:super struct:semigroup)
(define (semigroup/c a) (struct/dc semigroup [op (-> a a a)]))
(define (monoid/c a)
(struct/dc monoid [mempty a] [(op #:parent semigroup) (-> a a a)]))
我收到错误
struct/dc: expected an identifier that names a field or a sequence with a field name, the #:parent keyword, and the parent
struct
at: (op #:parent semigroup)
in: (struct/dc monoid (mempty a) ((op #:parent semigroup) (-> a a a)))
我没有看到我做错了什么。
我使用的是Racket 6.9。