-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more-complete-application RFC #756
base: master
Are you sure you want to change the base?
Conversation
That sounds great! |
TL;DR To fully benefit from these proposed changes, improvements Longer: After looking at an initial implementation of this feature and then
An example: With the improve function application (1), we can simplify [add1 (from-cases
(-> -Zero -One)
(-> -One -PosByte)
(-> -Byte -PosIndex)
(-> -Index -PosFixnum)
(-> -NegFixnum -NonPosFixnum)
(-> -NonPosFixnum -Fixnum)
(-> -Nat -Pos)
(-> -NegInt -NonPosInt)
(-> -Int -Int)
(-> -NonNegRat -PosRat)
(-> -Rat)
(-> -NonNegFlonum -PosFlonum)
(-> -Flonum)
(-> -NonNegSingleFlonum -PosSingleFlonum)
(-> -SingleFlonum)
(-> -NonNegInexactReal -PosInexactReal)
(-> -InexactReal)
(-> -NonNegReal -PosReal)
(-> -Real -Real)
(-> -FloatComplex -FloatComplex)
(-> -SingleFlonumComplex -SingleFlonumComplex)
(-> -InexactComplex -InexactComplex)
(-> N N))]
to this: [add1 (from-cases
(-> -Zero -One)
(-> -One -Byte)
(-> -Byte -Index)
(-> -Index -Fixnum)
(-> -NonPosFixnum -Fixnum)
(-> -NegInt -NonPosInt)
(-> -NonNegReal -PosReal)
(-> -InexactReal -InexactReal)
(-> -Int -Int)
(-> -Rat -Rat)
(-> -Flonum -Flonum)
(-> -SingleFlonum -SingleFlonum)
(-> -FloatComplex -FloatComplex)
(-> -SingleFlonumComplex -SingleFlonumComplex)
(-> -Real -Real)
(-> -InexactReal -InexactReal)
(-> -InexactComplex -InexactComplex)
(-> N N))] This seems nice... but we see someproblems if we consider a few First, in Typed Racket today: #lang typed/racket
(define x : Index 42)
(add1 x) ;; type checks at Positive-Fixnum
(ann add1 (-> Index Positive-Fixnum)) ;; type checks fine
(build-list x add1) ;; type checks at (Listof Positive-Fixnum) All three terms using If we improve only function application (so it uses all #lang typed/racket
(define x : Index 42)
(add1 x) ;; type checks at Positive-Fixnum
(ann add1 (-> Index Positive-Fixnum)) ;; fails to type check
(build-list x add1) ;; type checks at (Listof Fixnum) The first still type checks at The second fails to type check because subtyping is not reasoning The third type checks at a less precise type because inference does not |
TL;DR for
case->
types, we're proposing to apply allpossible
->
's to compute the return type instead ofjust the first applicable arrow.
Longer:
Some functions use a
case->
type, which indicates thatmultiple simpler function types work together to describe
the function's behavior.
For example, a simple addition function designed to add
integers with the same sign could be written as follows:
Old behavior: up until now, when type checking the application of a
case->
,Typed Racket searches for the first applicable arrow and then uses that
return type. E.g.,
New proposed behavior: when calculating the resulting type for specific
use cases, each applicable
->
type in thecase->
contributesto determining the result type:
In other words, the first two examples correspond to the
first and second arrows respectively, but the third example
fits both descriptions, and so the resulting type is the
intersection of both result types, i.e. the type which
describes values that are both nonnegative and nonpositive
integers (namely
Zero
).