test the example that would have been unsound

This commit is contained in:
AlexKnauth 2016-05-10 14:35:05 -04:00
parent c9110ccf73
commit 95d960267a
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#lang s-exp "../../mlish.rkt"
(require "../rackunit-typechecking.rkt")
(define-type (Option X)
None
(Some X))
(define (make-f → (→ A A))
(let ([r (ref (None {A}))])
(λ (x)
(let ([y (deref r)])
(begin
(:= r (Some x))
(match y with
[None -> x]
[Some y -> y]))))))
;; This has to fail, because if could succeed with the type (→ A A),
;; then it could cause unsoundness.
(typecheck-fail (make-f) #:with-msg "Could not infer instantiation of polymorphic function make-f.")
; ;; If f were defined as the result of (make-f), then it would result
; ;; in unsoundess if these two expressions were also accepted:
; (f 13)
; ;; Because this would typecheck as a String even though it returns 13, an Int:
; (f "foo")

View File

@ -5,6 +5,7 @@
(require "mlish/match2.mlish")
(require "mlish/polyrecur.mlish")
(require "mlish/loop.mlish")
(require "mlish/value-restriction-example.mlish")
;; (require "mlish/trees.mlish")
;; (require "mlish/chameneos.mlish")