Frontend.Typechecker
a type/semantic checker for Stan ASTs
Functions which begin with "check_" return a typed version of their input Functions which begin with "verify_" return unit if a check succeeds, or else throw an Frontend.Errors.SemanticError
exception. Other functions which begin with "infer"/"calculate" vary. Usually they return a value, but a few do have error conditions.
All Error.SemanticError
excepetions are caught by check_program which turns the ast or exception into a Result.t
for external usage
A type environment Frontend.Environment.t
is used to hold variables and functions, including Stan math functions. This is a functional map, meaning it is handled immutably.
val check_program_exn :
Ast.untyped_program ->
Ast.typed_program * Warnings.t list
Type check a full Stan program. Can raise Errors.SemanticError
val check_program :
Ast.untyped_program ->
(Ast.typed_program * Warnings.t list, Semantic_error.t) Stdlib.result
The safe version of check_program_exn
. This catches all Errors.SemanticError
exceptions and converts them into a Result.t
val operator_stan_math_return_type :
Middle.Operator.t ->
(Middle.UnsizedType.autodifftype * Middle.UnsizedType.t) list ->
(Middle.UnsizedType.returntype * Promotion.t list) option
val stan_math_return_type :
string ->
(Middle.UnsizedType.autodifftype * Middle.UnsizedType.t) list ->
Middle.UnsizedType.returntype option
A reference to hold the model name. Relevant for checking variable clashes and used in code generation.