FLAT: Formal Languages as Types
Fengmin Zhu, Andreas Zeller

TL;DR
This paper introduces FLAT, a novel approach that treats formal languages as types to improve type safety in programming, demonstrated through a Python framework that detects bugs by enforcing language-based string constraints.
Contribution
It proposes the innovative concept of using formal languages as types and implements it in Python with FLAT-PY for runtime type checking and bug detection.
Findings
FLAT-PY effectively detects logical bugs in Python code.
Language-based annotations enable precise type distinctions.
The framework requires reasonable user effort for effective bug detection.
Abstract
Programmers regularly use strings to encode many types of data, such as Unix file paths, URLs, and email addresses, that are conceptually different. However, existing mainstream programming languages use a unified string type to represent them all. As a result, their type systems will keep quiet when a function requiring an email address is instead fed an HTML text, which may cause unexceptional failures or vulnerabilities. To let the type system distinguish such conceptually different string types, in this paper, we propose to regard \emph{formal languages as types} (FLAT), thereby restricting the set of valid strings by context-free grammars and semantic constraints if needed. To this end, email addresses and HTML text are treated as different types. We realize this idea in Python as a testing framework FLAT-PY. It contains user annotations, all directly attached to the user's code,…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsModel-Driven Software Engineering Techniques
