rebellion
rebellion copied to clipboard
Guards for tuple types
Part of #42. Tuple types should allow guards. The signature of a wrapper guard should match the contract (-> wrapper-type? any/c ... any)
, accepting an argument with information about the tuple type (in order to use the type name in error messages, for instance) and one additional argument for each field value being wrapped. It should return a value for each field representing the replacement value to use for that field (possibly normalized to some canonical form, or wrapped with a chaperone, etc.).
Then, the make-tuple-implementation
function and the define-tuple-type
macro should both accept an optional #:guard
parameter matching this contract. As a convenience, a (tuple-guard/c contract)
contract combinator should construct a function suitable for use with the #:guard
option that simply checks the field with the contract.
This should be one of the most straightforward type guards to implement, since it directly maps to how struct guards work.
Updated design: the acceptance of the tuple type info and the acceptance of the instance fields should be separated by a partial application barrier. Meaning, the contract for a tuple guard should actually be (-> tuple-type? (-> any/c ... any))
, to allow tuple guards to raise an error if the tuple type information they're given is wrong. The tuple-guard/c
combinator should use this property to check that the number of fields in the tuple type matches up with the number of contracts that were given to tuple-guard/c
.