
Adds intersection types as a better way to handle the the case when restrict cannot structurally intersect two types (e.g. when you learn within a polymorphic function a variable x of type A is also an Integer, but we dont know how A relates to Integer). This allows for non-lossy refinements of type info while typechecking.
20 lines
284 B
Racket
20 lines
284 B
Racket
#lang racket/base
|
|
|
|
|
|
(module a typed/racket
|
|
(provide num-id)
|
|
(: num-id (∀ (A) (-> (∩ Number A) (∩ Number A))))
|
|
(define (num-id x) x))
|
|
|
|
(require 'a)
|
|
|
|
(let ()
|
|
(num-id 42)
|
|
(void))
|
|
|
|
(with-handlers ([exn:fail:contract?
|
|
(λ (ex) (void))])
|
|
(num-id "42"))
|
|
|
|
|