[Libre-soc-dev] liskov substitution principle and type assertions/annotations
Jacob Lifshay
programmerjake at gmail.com
Fri Aug 12 21:07:13 BST 2022
On Fri, Aug 12, 2022, 09:48 Hendrik Boom via Libre-soc-dev <
libre-soc-dev at lists.libre-soc.org> wrote:
> If you rally wanted a language that's compact and strongly type-checked,
> you would have chosen OCaml, not Python or C++.
>
> Almost no OCaml programmers bother with declaring types on all their
> functions, but the compiler still manages to check them.
>
interestingly, Rust is derived from OCaml, the compiler was originally
written in OCaml and morphed into Rust.
Rust needs nearly no type declarations except at function inputs/outputs,
because it has both forward and backward type deduction, e.g.:
let a = Vec::new(); // Vec with deduced element type
// causes a to be deduced as Vec<MyType>, since that's what the function
returns.
a.push(my_fn_that_returns_my_type());
They intentionally require types at API boundaries (mostly function
inputs/outputs) so you don't have the issue of global type deduction where
you change one use of something and it's type unexpectedly changes
throughout your whole program, including in code other people wrote that
expects the type not to change.
Jacob
More information about the Libre-soc-dev
mailing list