Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixpulvis/648386b2f742be89900e to your computer and use it in GitHub Desktop.
Save nixpulvis/648386b2f742be89900e to your computer and use it in GitHub Desktop.
Simplest Contract System
#lang racket
;; A Contract is one of:
;; - Any -> Boolean
;; - Signature
;; A Signature is a (signature Contract Contract)
(struct signature (domain range))
(define (assert-prop p v)
(if (p v) v (error "contract failed")))
(define (assert-signature c v)
(lambda (x)
(assert (signature-range c)
(v (assert (signature-domain c) x)))))
(define (assert c v)
(match c
[(? signature?) (assert-signature c v)]
[(? procedure?) (assert-prop c v)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment