Strange behaviors of match's or pattern
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 575
- Forks
- 106
- Avg merge
- 2h 1m
- Merged PRs (30d)
- 2
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the three typed/racket programs from the issue under Racket v7.8 and compare their or patterns with the equivalent separate match clauses. Investigate the reported false or widened types and the endless loop; done means all three programs type-check and produce the expected procedure behavior without looping.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100