Types and Neural Networks

brunogavranovic.com
April 21, 2026
13 min read
🔥🔥🔥🔥🔥
48/100
Summary
Neural networks are utilized to generate code in languages such as Idris, Lean, and Agda, which support generic and provably correct programming. Large Language Models produce output of a fixed type, List Token, and require post-processing for typechecking to ensure the validity of the generated code.
Key Takeaways
- Neural networks can generate code in languages that support generic and provably correct programming, such as Idris, Lean, and Agda.
- Current large language models (LLMs) are trained to produce output of a fixed type and rely on post-training parsing to achieve valid code.
- Two main approaches for type enforcement in LLMs are "Try; Compile; If Error Repeat," which consults the typechecker after generation, and "Constrained decoding," which checks types before each token is sampled.
- The "Try; Compile; If Error Repeat" method can be inefficient as it may generate invalid sequences that are only detected after full completion, leading to wasted processing.
Community Sentiment
Positives
- The approach of encoding programming languages into training data allows models to leverage scale effectively, potentially improving their generative capabilities.
- Utilizing structured outputs and templates for well-typed code generation could enhance the reliability of AI-generated code, addressing common errors.
Concerns
- Relying solely on tokenization and next-word prediction limits models' understanding, as it fails to replicate human-like learning and reasoning processes.
- Current methods for type-constrained generation are inference-time solutions that do not update model weights, which may hinder long-term learning and adaptation.




