I have a funny case in TR where occurrence typing loses information about the 
type of a term:

#lang typed/racket

(: expand (Sexp -> Sexp))
(define (expand s)
  (match s
    [(list (? symbol? id) a ...)
     s]))

This fails to type check, because the occurrence of ’s’ in the rhs of the match 
is no longer known to be an Sexp. Specifically, I get the message:

Type Checker: type mismatch
  expected: Sexp
  given: (Pairof
          Symbol
          (U Null (Pairof Sexp (U Null (Pairof Sexp (Listof Any)))))) in: s

I understand that the (Pairof …) type arises from the expansion of match, but 
it seems unfortunate that TR can’t compute the intersection of the two types 
known to hold for ’s’ to arrive at 

(Pairof Symbol (U Null (Pairof Sexp (U Null (Pairof Sexp (Listof Sexp))))))

… which is a subtype of Sexp, and therefore legal to return as an Sexp.

Is there perhaps a hinting mechanism by which I could suggest to TR that it 
look at the original type known to be associated with ’s’? Or perhaps there’s a 
depth limit on the intersection computation that I’m running into? Or perhaps 
I’m misunderstanding the situation entirely?

John

p.s.: I can obviously work around this problem with a ‘cast’.

[*] “weakens” may not be an appropriate term here, given that neither of the 
two types discussed are subtypes of the other.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to