Is there a way to define alongside a (typed) structure a contract for the entire structure in Typed Racket? In my particular case, I have a structure that takes two lists as fields, and I want to require the lists to be the same length.
I've looked at:
make-struct-type
, which allows specification of a "guard" that moderates constructor calls. I could pass a procedure that raises an exception if the lengths don't match, but I don't know what to do with the values returned bymake-struct-type
.struct/c
and thestruct
form ofcontract-out
, both of which produce structure contracts from contracts on individual fields. This seems unhelpful here.
Ideally I would like to bind the contract to the structure immediately (as in define/contract
), but I'm open to adding the contract when I provide
the type's procedures. However, I currently provide the recognizer and accessor procedures individually rather than using struct-out
(so that I can exclude or rename individual procedures), and I'd like to keep that flexibility.
Right now I have something like this:
(provide
(rename-out
[MyStruct my-struct]
[MyStruct? my-struct?]
[MyStruct-foo my-struct-foo]
[MyStruct-bar my-struct-bar]
)
)
(struct MyStruct (
[foo : (Listof Symbol)]
[bar : (Listof Any)]
))