Fighting with racket type-system & match

Following program defines 3 types and one function which tries to match the 3 types.
The error given is : "match syntax error in pattern in : (stc x)
Obvious question why ?

#lang typed/racket
(require  racket/match )
(define-struct dsa ([ A : [U 'plus 'minus] ]))
(struct sb ([ B : Number]))
(define-type   stc (U dsa sb))

(define f1
  (lambda (x)
    (match (x)
      [(dsa A) 1]
      [(sb B) 2]
      [(stc x) 3]
      )
    )
  )

The main issue is that stc is not a struct constructor, it's "just" a type. On the other hand, dsa and sb are both struct constructors and types. They can be used at runtime like (dsa 'plus), (dsa 'minus), (sb 0), and so on, but stc cannot be used like that.

Also, do you want f1 to take an stc, or do you want it to take a function that produces an stc?

3 Likes