Master the fundamental concepts of semantic analysis through this focused micro-challenge.
ML, Haskell, Rust, and TypeScript infer types where annotations are omitted. Hindley-Milner unification assigns types to every subexpression; Rust's solver handles traits. Even a simple constraint-based inferencer for arithmetic expressions teaches the core idea.
Literals get concrete types: 42 is int, 3.14 is float. For a + b, unify a and b to the same numeric type; result matches. For if c then e1 else e2, unify e1 and e2; c must be bool.
cLoading…
add : int -> int -> int or polymorphicProduction compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement type inference for a small expression language without explicit type annotations. This exercise requires generating constraints from the AST and solving them to assign types to every subexpression.
Implement type inference for a simple expression language.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github