question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to typecheck `let`-expressions?

See original GitHub issue

I’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 some A uses B then A depends on B too);
  • When typechecking a definition and we meet a let-expression, we form a dependency graph of the module of the let-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, the localCtx has the variables of the outer definition.
  • Hence, we should not lift the definitions of let-expressions outside like we did to modules; because this way we could not ensure the localCtx. We should typecheck them only when we meet them, at that time the localCtx 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 the let-expression. So when we check the let-expression, its dependencies are all checked too.
  • Another definition outside cannot depend on a definition inside let-expression at all.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
ice1000commented, Apr 17, 2021
  • 👍 for having local modules
  • 👎 for simple let like in Arend

@re-xyr is not allowed to cast vote

0reactions
ice1000commented, Dec 8, 2022

Fixed!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found