by serialdev · 8y ago · 0 comments
The SBCL compiler actually has a type inference engine built in to it.
> compile time type checking
Aren't those the same thing?
For example if you know that + is defined for numbers, then you can inference that a and b must be numbers: (+ a b)
If you know that a and b are numbers then you can inference that subexpressions need to deal with numbers only:
(let ((a c) (b d)) (declare (type number a b)) ....)
The type inferencer then will tell what types the various expressions have. It will try to propagate known types as widely as possible in the code.Allegro CL and LispWorks for example are doing this type inference. But their compiler will not tell you that type declarations are violated.
SBCL OTOH treats type declarations as type assertions which can be checked at compile time. ADDITIONALLY it also does type inference - and additionally uses this information for compile time type checks.
A compile time type checker is expected to signal errors at compile time for programs whose types don't check out.
You can use a type inferencer without signaling any errors at compile time (for example, by deferring errors to runtime) and you can signal type errors at compile time even if you don't infer any types (like C compilers, that demand all variables have a declared type).