Use correct contract for Procedure type

The only problem with this contract is that it does
not produce a very good error message

original commit: 27d3042ad6008432428368bda882987f1f8a23c1
This commit is contained in:
Asumu Takikawa 2013-01-08 16:15:12 -05:00
parent 30da00ba79
commit 04bc05d607
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,23 @@
#;
(exn-pred exn:fail:contract:arity?)
#lang racket/load
;; fail version
(module example typed/racket
;; coerces into unapplicable function
(: id (Procedure -> Procedure))
(define (id x) x)
(: f (Integer -> Integer))
(define (f x) (+ x 1))
(define g (id f))
;; contract here should make sure g is not applicable
(provide g))
(require 'example)
;; g should now be unapplicable via case-> contract
(g 3)

View File

@ -0,0 +1,21 @@
#lang racket
;; succeed version
(module example typed/racket
;; coerces into unapplicable function
(: id (Procedure -> Procedure))
(define (id x) x)
(: f (Integer -> Integer))
(define (f x) (+ x 1))
(define g (id f))
;; contract here should allow application
(provide id))
(require 'example)
;; id's argument is procedure?, result is (case->)
(id +)

View File

@ -129,7 +129,7 @@
(loop t (not pos?) (not from-typed?) structs-seen kind))
(define (t->c/fun f #:method [method? #f])
(match f
[(Function: (list (top-arr:))) #'procedure?]
[(Function: (list (top-arr:))) (if pos? #'(case->) #'procedure?)]
[(Function: arrs)
(set-chaperone!)
;; Try to generate a single `->*' contract if possible.