Skip to content

Conversation

@bennn
Copy link
Contributor

@bennn bennn commented May 5, 2018

RFC for #707

Goals:

  • identify all kinds of function applications in Typed Racket (applying a normal function, applying a dependent function, the special cases in typecheck/tc-app/*)
  • have a complete RFC

@bennn bennn self-assigned this May 5, 2018
@bennn bennn force-pushed the evaluation-order-rfc branch from cfa85d5 to aa5afb9 Compare May 6, 2018 04:02
@MichaelBurge
Copy link
Contributor

MichaelBurge commented May 6, 2018

Should evaluation order affect typechecking?

In the expression

(+ x (begin (assert x integer?) x))

the right-hand x is known to be an integer. But the left-hand x is the same x: Since all arguments are evaluated before the function is invoked, it shouldn't be unsound if earlier arguments are accepted on the basis of later arguments passing their runtime checks.

Do we want the union of all propositions to apply to each argument?

Probably not - if the left-hand x is changed to (f x) for some f expecting an integer?, then it would be unsound. So it would only help in the cases where a variable is passed unmodified to the function application. Although that does make me wonder if asserts should be pushed to the beginning of the scope.

RFC for accumulating unconditional propositional when typechecking a
function application (accumulate from left-to-right, same as evaluation
will go)
@bennn
Copy link
Contributor Author

bennn commented May 6, 2018

Do we want the union of all propositions to apply to each argument?

No, because that could be unsound. In this application, we don't want to check the 1st argument to + assuming that x is an integer:

(+ (add1 x) (begin (assert x integer?) x))

I think we need to conservatively reject your example.

@pnwamk pnwamk added the RFC Includes an RFC label May 7, 2018
@pnwamk
Copy link
Member

pnwamk commented May 7, 2018

Would it be helpful to describe this as checking function application in terms of its equivalent expansion into A-normal form to help with intuition as for why it works and is correct?

i.e. we're basically leveraging the fact that checking this program:

(fun arg1 arg2 ...)

is equivalent to checking this one:

(let* ([x1 arg1]
       [x2 arg2]
       ...)
  (fun x1 x2 ...))

(where the x's are fresh) because of how function application is defined in Racket. (I know that the let* could have been a let but perhaps the * helps emphasize the necessary ordering of argument evaluation for people who haven't realized let also guarantees in-order evaluation in Racket)

@samth samth marked this pull request as draft January 23, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-progress RFC Includes an RFC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants