Skip to content

Instantly share code, notes, and snippets.

@takikawa
Last active December 18, 2015 00:59
Show Gist options
  • Save takikawa/5701053 to your computer and use it in GitHub Desktop.
Save takikawa/5701053 to your computer and use it in GitHub Desktop.
#lang typed/racket
(define-type (Even A) (U Null (Pairof A (Odd A))))
(define-type (Odd A) (Pairof A (Even A)))
(: even-lst (Even Integer))
(define even-lst '(1 2 3 4))
(: odd-lst (Odd Integer))
(define odd-lst '(1 2 3))
(: even->odd (All (A) (A (Even A) -> (Odd A))))
(define (even->odd elem lst)
(cons elem lst))
(provide even->odd Even Odd
even-lst odd-lst)
-> (even->odd 1 '(1))
; even->odd: contract violation
; expected: pair?
; given: '()
; in: the cdr of
; a disjunct of
; the 2nd argument of
; (->
; any/c
; (recursive-contract
; (or/c
; null?
; (cons/c
; any/c
; (recursive-contract
; (cons/c ctc27 (Even122 ctc27))
; #:chaperone)))
; #:chaperone)
; (recursive-contract
; (cons/c
; any/c
; (recursive-contract
; (or/c
; null?
; (cons/c ctc35 (Odd230 ctc35)))
; #:chaperone))
; #:chaperone))
; contract from:
; <collects>/tests/typed-racket/even-odd.rkt
; blaming: top-level
; at: <collects>/tests/typed-racket/even-odd.rkt:27.9
; [,bt for context]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment