> On May 27, 2016, at 4:24 PM, 'John Clements' via Racket Users 
> <[email protected]> wrote:
> 
> 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.

In the latest snapshot versions, this type-checks. It might be because of the 
addition of Andrew Kent's intersection types, because according to DrRacket the 
type of the `s` in the body is:

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

which is a subtype of Sexp.

For previous versions, a workaround I've used is to add an extra `my-identity` 
function to fool it it so that it doesn't realize that I'm applying a predicate 
to `s` or matching on it.

> 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