Open
Description
What version of Racket are you using?
v7.8
What program did you run?
Program 1:
#lang typed/racket
(define-type Type (U Number Symbol))
(ann (lambda (arg)
(match arg
[(or (? number? x)
(? symbol? x))
x]))
[-> Type Type])
Program 2:
#lang typed/racket
(define-type Variable (Refine [var : Symbol] (! var 'λ)))
(define-predicate variable? Variable)
(define-type Type (U Number Variable))
(ann (lambda (arg)
(match arg
[(or (? number? x)
(? variable? x))
x]))
[-> Type Type])
Program 3:
#lang typed/racket
(define-type Variable (Refine [var : Symbol] (! var 'λ)))
(define-predicate variable? Variable)
(define-type Type (U Number Variable (Listof Type)))
(ann (lambda (arg)
(match arg
[(or (? number? x)
(? variable? x))
x]))
[-> Type Type])
What should have happened?
Print a procedure.
If I change or
pattern to 2 different patterns in match
, the above codes will work properly.
(match arg
[(? number? x) x]
[(? variable? x) x])
If you got an error message, please include it here.
Program 1: Why could x
be False
type?
Type Checker: type mismatch
expected: Type
given: (U False Type)
in: x
Program 2: Why could x
be Symbol
type instead of Variable
type?
Type Checker: type mismatch
expected: Type
given: (U Complex False Symbol)
in: x
Program 3: The program stucks in an endless loop.