How to typecheck `let`-expressions?
See original GitHub issueI’ve been thinking about the details of this. Firstly, if we don’t have let
-expressions, we only have to detect all definitions at the top-level and submodules and form a dependency graph out of it. However if we have let
-expressions, I think the solution is like this:
- Detect all top-level definitions and submodule definitions (but not definitions in
let
-expressions); - Form a dependency graph out of them (note that if some def
C
in someA
usesB
thenA
depends onB
too); - When typechecking a definition and we meet a
let
-expression, we form a dependency graph of the module of thelet
-expression, typecheck them, and go on.
Why not directly form a dependency graph out of all definitions, including those in the let
-expressions?
- We need to ensure that when we typecheck
let
-expressions, thelocalCtx
has the variables of the outer definition. - Hence, we should not lift the definitions of
let
-expressions outside like we did tomodule
s; because this way we could not ensure thelocalCtx
. We should typecheck them only when we meet them, at that time thelocalCtx
will be complete.
Why won’t this cause a problem in dependency?
- If the def in
let
-expression depends on another definition outside, then that definition is also depended on by the outer definition of thelet
-expression. So when we check thelet
-expression, its dependencies are all checked too. - Another definition outside cannot depend on a definition inside
let
-expression at all.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13 (13 by maintainers)
Top Results From Across the Web
COS 326: Functional Programming
This means that to type check an expression, one needs to know the types ... Let expressions that define functions rather than simple...
Read more >CS312 Lecture 21 Type Checking
Therefore we want to be able to type-check a program e -- that is, implement tcheck(e) -- by recursively applying tcheck to all...
Read more >Assignment 7: Type Checking & Subtyping
Implement typechecking, by translating the rules of a type system into code. ... Typecheck simple (non-tuple) let -expressions.
Read more >Type Checking
Essentially, have to type check each construct ... Result of a type check is a ExpTy object which ... Declarations only appear in...
Read more >Type Checker For Paret - Brown CS
We have defined a function fun type-check(prog :: String) -> Type that calls parse ... so it contains let expressions that your type-checker...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
let
like in Arend@re-xyr is not allowed to cast vote
Fixed!