syndicate-2017/racket/typed/tests/expressions.rkt

37 lines
821 B
Racket
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#lang typed/syndicate/roles
(require rackunit/turnstile)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Type Abstraction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define id
(Λ [τ]
(lambda ([x : τ])
x)))
(check-type id : ( (τ) (→fn τ τ)))
(check-type ((inst id Int) 1)
: Int
1)
(check-type ((inst id String) "hello")
: String
"hello")
(define poly-first
(Λ [τ σ]
(lambda ([t : (Tuple τ σ)])
(select 0 t))))
(check-type poly-first : ( (A B) (→fn (Tuple A B) A)))
(check-type ((inst poly-first Int String) (tuple 13 "XD"))
: Int
13)
(check-type ((inst poly-first Int String) (tuple 13 "XD"))
: Int
13)