Created
August 20, 2014 16:24
-
-
Save samth/1e12f9aa6e97536b6e90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(define-struct contract-property [ name | |
first-order | |
projection | |
stronger | |
generate | |
exercise | |
val-first-projection | |
list-contract? ] | |
#:omit-define-syntaxes) | |
(define (contract-property-guard prop info) | |
(unless (contract-property? prop) | |
(raise | |
(make-exn:fail:contract | |
(format "~a: expected a contract property; got: ~e" | |
'prop:contract | |
prop) | |
(current-continuation-marks)))) | |
prop) | |
(define-values [ prop:contract contract-struct? contract-struct-property ] | |
(make-struct-type-property 'prop:contract contract-property-guard)) | |
(define-struct chaperone-contract-property [implementation] | |
#:omit-define-syntaxes) | |
(define (chaperone-contract-property-guard prop info) | |
(unless (chaperone-contract-property? prop) | |
(raise | |
(make-exn:fail:contract | |
(format "~a: expected a chaperone contract property; got: ~e" | |
'prop:chaperone-contract | |
prop) | |
(current-continuation-marks)))) | |
prop) | |
;; We check to make sure the contract projection actually resulted in | |
;; a chaperone (or chaperone-friendly) version of the value. | |
(define (chaperone-contract-property->contract-property fc) | |
(let ([impl (chaperone-contract-property-implementation fc)]) | |
impl)) | |
(define-values [ prop:chaperone-contract | |
chaperone-contract-struct? | |
chaperone-contract-struct-property ] | |
(make-struct-type-property | |
'prop:chaperone-contract | |
chaperone-contract-property-guard | |
(list (cons prop:contract chaperone-contract-property->contract-property)))) | |
(struct p () | |
#:property prop:chaperone-contract (make-chaperone-contract-property | |
(make-contract-property 0 0 values 0 0 0 0 0))) | |
(define (contract-struct-projection c) | |
(let* ([prop (contract-struct-property c)] | |
[get-projection (contract-property-projection prop)] | |
[projection (get-projection c)]) | |
projection)) | |
(contract-struct-projection (p)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment