Companion repository for the YouTube video: Type Inference Explained
TypeFighter is an educational type inference system implementation in F# that demonstrates how type systems work internally. This repository allows you to explore and experiment with type inference concepts interactively.
This project helps you understand type inference by:
- Providing runnable examples that visualize type inference steps
- Demonstrating various type system features (polymorphism, records, pattern matching, etc.)
- Offering an interactive AST visualization tool
-
Clone the repository
git clone https://github.com/SchlenkR/TypeFighter.git cd TypeFighter -
Restore .NET dependencies
dotnet restore
-
Install visualization dependencies
npm install
-
Start the visualization server
npm start
This launches the AST visualizer at
http://localhost:5173(or similar).
- Open
src/TypeFighter.Tests/video_00/the-example.fsxin VS Code - Select the top section (the setup code)
- Press
Alt+Enter(orCmd+Enteron macOS) to evaluate it in F# Interactive - Now evaluate each small program block individually to see type inference in action
- Check the visualization webpage to see the AST and type inference steps
The src/TypeFighter.Tests/TestCases/ directory contains comprehensive examples:
Base.fs- Basic type inferencePolymorphism.fs- Generic types and polymorphismRecords.fs- Record typesArrays.fs- Array and collection typesPatternMatching.fs- Pattern matching with typesIntersectionTypes.fs- Intersection type featuresTypeHierarchies.fs- Type hierarchies and subtypingMisc.fs- Additional scenarios
All test files are executable in F# Interactive following the same pattern as the-example.fsx.
TypeFighter/
├── src/
│ ├── TypeFighter/ # Core type inference engine
│ │ ├── Lang.fs # Language definition and types
│ │ ├── ExpressionDsl.fs # DSL for building expressions
│ │ └── Utils.fs # Utilities
│ ├── TypeFighter.Tests/ # Examples and test cases
│ │ ├── video_00/ # Video companion examples
│ │ └── TestCases/ # Feature examples
│ └── visu/ # AST visualization tool (TypeScript)
├── package.json # npm dependencies for visualization
└── TypeFighter.sln # .NET solution file
dotnet buildOr use the VS Code build task: TypeFighter (NonGraphBased): build dotnet solution
The visualization tool displays the Abstract Syntax Tree (AST) and type inference process. After starting the dev server with npm start, it automatically updates as you evaluate expressions in F# Interactive.
If you are interested in using this project, please contact me directly for permission.
This project was created as educational material to accompany the type inference video tutorial. Feel free to explore, learn, and experiment with the code for educational purposes.
Questions or feedback? Feel free to open an issue or reach out!