[Type Racket] Why doesn't this code type check?

31 views
Skip to first unread message

Weixi Ma

unread,
Dec 21, 2019, 9:46:18 AM12/21/19
to Racket Users
Hi guys, thanks for your attention. Here is the code.

1 (: n (U False Number))
2 (define n #f)
3 (when n
4   (set! n (sub1 n)))

I suppose there should a refinement at line 3 that narrows down the type of n to be Number.
However typed racket complains that n is expected to be Number and actually given (U Complex False).

Sam Tobin-Hochstadt

unread,
Dec 21, 2019, 9:48:14 AM12/21/19
to Weixi Ma, Racket Users
Typed Racket doesn't refine the type of mutable variables. Doing that soundly would require an effect and escape analysis that seems like more complexity than it's worth. 

Sam

--
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 racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/bdd02c94-e1e4-40b2-b0ba-608281c75f5a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages