Typle.Inference.Pattern
(Typle v0.3.1)
View Source
Extracts variable type bindings from pattern matches.
Given a pattern AST and the type of the expression being matched, narrows the type to the subset compatible with the pattern structure, decomposes composite types (tuples, lists, maps) into their element types, and propagates those types to bound variables.
Also records the inferred type at each variable's source position
so that Typle.type_at/3 can report pattern-variable types.
Summary
Functions
Infers variable types from a pattern, given the type of the matched expression.
Types
@type bindings() :: %{required(atom()) => Typle.Type.t()}
@type positions() :: %{ required({non_neg_integer(), non_neg_integer()}) => {Typle.Type.t(), String.t() | nil} }
Functions
@spec infer(Macro.t(), Typle.Type.t()) :: {bindings(), positions()}
Infers variable types from a pattern, given the type of the matched expression.
Returns {bindings, positions} where bindings maps variable names to
their inferred types and positions maps {line, col} to the type at
that source location.