Generic bidirectional typing for dependent type theories

Read original: arXiv:2307.08523 - Published 4/3/2024 by Thiago Felicissimo
Total Score

0

🏋️

Sign in to get full access

or

If you already have an account, we'll log you in

Overview

  • Bidirectional typing is a technique for controlling the flow of type information in typing rules and specifying how they should be used.
  • Bidirectional typing has been studied and applied to many type theories, but the formal development has been confined to specific theories.
  • This work presents a generic approach to bidirectional typing for a broad class of dependent type theories.

Plain English Explanation

Bidirectional typing is a way of breaking down the typing process into two steps: inference and checking. In the inference step, the system tries to figure out the type of an expression based on the context. In the checking step, the system verifies that the expression actually has the type it inferred.

This separation of inference and checking allows for more control over how type information flows through the typing rules. It's like having a traffic cop directing the flow of cars (type information) through an intersection (the typing rules), making sure everything goes smoothly.

The authors of this paper wanted to develop a general framework for bidirectional typing that could be applied to a wide range of type theories, rather than being limited to a specific theory. This would make it easier to use bidirectional typing in different settings and allow for more flexibility and reuse.

Technical Explanation

The paper first provides a general definition of type theories, which can be thought of as a logical framework for defining different type systems. The authors then define both a declarative type system and a bidirectional type system within this framework.

They then prove that the declarative and bidirectional type systems are equivalent, meaning they produce the same typing judgments. This is an important result because it shows that the bidirectional system is a sound and complete implementation of the declarative system.

The authors also use this equivalence to establish the decidability of typing for weakly normalizing type theories, meaning there is a guaranteed algorithm for determining the type of an expression. They have implemented this algorithm in a prototype and used it with various type theories in practice.

Critical Analysis

The paper presents a robust and general framework for bidirectional typing, which is a significant contribution to the field. By developing a theory-independent approach, the authors have made bidirectional typing more accessible and easier to apply to a wider range of type systems.

However, the paper does not address the performance implications of the bidirectional typing algorithm. While it is guaranteed to terminate, the actual efficiency of the algorithm is not discussed. Additionally, the paper does not provide any empirical evaluation of the algorithm's performance in practice.

Furthermore, the paper focuses on the theoretical development of the framework and does not delve into potential applications or use cases. Exploring how this generic bidirectional typing approach can benefit real-world type systems and programming languages would be a valuable next step.

Conclusion

This paper presents a comprehensive, theory-independent approach to bidirectional typing, which is an important technique for controlling the flow of type information in typing rules. By proving the equivalence between declarative and bidirectional type systems, the authors have laid the groundwork for developing efficient and reliable type-checking algorithms that can be applied across a wide range of type theories. While further research is needed to assess the practical performance and potential applications of this framework, the work represents a significant advancement in the formal understanding and implementation of bidirectional typing.



This summary was produced with help from an AI and may contain inaccuracies - check out the links to read the original source documents!

Follow @aimodelsfyi on 𝕏 →

Related Papers

🏋️

Total Score

0

Generic bidirectional typing for dependent type theories

Thiago Felicissimo

Bidirectional typing is a discipline in which the typing judgment is decomposed explicitly into inference and checking modes, allowing to control the flow of type information in typing rules and to specify algorithmically how they should be used. Bidirectional typing has been fruitfully studied and bidirectional systems have been developed for many type theories. However, the formal development of bidirectional typing has until now been kept confined to specific theories, with general guidelines remaining informal. In this work, we give a generic account of bidirectional typing for a general class of dependent type theories. This is done by first giving a general definition of type theories (or equivalently, a logical framework), for which we define declarative and bidirectional type systems. We then show, in a theory-independent fashion, that the two systems are equivalent. This equivalence is then explored to establish the decidability of typing for weak normalizing theories, yielding a generic type-checking algorithm that has been implemented in a prototype and used in practice with many theories.

Read more

4/3/2024

Inferring Pluggable Types with Machine Learning
Total Score

0

Inferring Pluggable Types with Machine Learning

Kazi Amanul Islam Siddiqui, Martin Kellogg

Pluggable type systems allow programmers to extend the type system of a programming language to enforce semantic properties defined by the programmer. Pluggable type systems are difficult to deploy in legacy codebases because they require programmers to write type annotations manually. This paper investigates how to use machine learning to infer type qualifiers automatically. We propose a novel representation, NaP-AST, that encodes minimal dataflow hints for the effective inference of type qualifiers. We evaluate several model architectures for inferring type qualifiers, including Graph Transformer Network, Graph Convolutional Network and Large Language Model. We further validated these models by applying them to 12 open-source programs from a prior evaluation of the NullAway pluggable typechecker, lowering warnings in all but one unannotated project. We discovered that GTN shows the best performance, with a recall of .89 and precision of 0.6. Furthermore, we conduct a study to estimate the number of Java classes needed for good performance of the trained model. For our feasibility study, performance improved around 16k classes, and deteriorated due to overfitting around 22k classes.

Read more

6/26/2024

💬

Total Score

0

Stream Types

Joseph W. Cutler, Christopher Watson, Emeka Nkurumeh, Phillip Hilliard, Harrison Goldstein, Caleb Stanford, Benjamin C. Pierce

We propose a rich foundational theory of typed data streams and stream transformers, motivated by two high-level goals: (1) The type of a stream should be able to express complex sequential patterns of events over time. And (2) it should describe the internal parallel structure of the stream to support deterministic stream processing on parallel and distributed systems. To these ends, we introduce stream types, with operators capturing sequential composition, parallel composition, and iteration, plus a core calculus lambda-ST of transformers over typed streams which naturally supports a number of common streaming idioms, including punctuation, windowing, and parallel partitioning, as first-class constructions. lambda-ST exploits a Curry-Howard-like correspondence with an ordered variant of the logic of Bunched Implication to program with streams compositionally and uses Brzozowski-style derivatives to enable an incremental, prefix-based operational semantics. To illustrate the programming style supported by the rich types of lambda-ST, we present a number of examples written in delta, a prototype high-level language design based on lambda-ST.

Read more

4/4/2024

Activation Steering for Robust Type Prediction in CodeLLMs
Total Score

0

Activation Steering for Robust Type Prediction in CodeLLMs

Francesca Lucchetti, Arjun Guha

CodeLLMs are transforming software development as we know it. This is especially true for tasks where rule-based approaches fall short, like type prediction. The type prediction task consists in adding a new type annotation to a partially typed program, such that the resulting program is closer to being fully typed. The intractability of rule-based approaches and high cost of manual annotation make CodeLLMs an attractive solution to the problem. However, CodeLLMs are still far from being deployed on the large-scale due to doubts surrounding their reliability. To shed some light on how CodeLLMs approach type prediction, we investigate what happens when a model mispredicts a type. We show that by applying semantics-preserving edits to code, CodeLLMs are eventually misled into mispredicting type annotations. However, by leveraging activation steering we are able to steer the model back to the correct prediction, making models more robust against semantically irrelevant prompt features. We show that steering achieves comparable performance to fine-tuning directly on the type prediction task. Furthermore, we find that steering vectors computed from Python code are effective at correcting TypeScript mispredictions, and vice versa. To our knowledge, this is the first evidence of its kind to suggest that CodeLLMs learn task representations that transfer across languages.

Read more

9/16/2024