Skip to content

Strange behaviors of match's or pattern #975

Open
@NoahStoryM

Description

@NoahStoryM

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions