Hacker News new | ask | show | jobs
by stass 7 days ago
I would totally use a different language whenever it fits. The compiler for Type-C itself is written in OCaml because C is terrible for parsers, and I have a whole microkernel OS project where most of it, including all drivers, is written in Erlang.

This is not always possible, however, especially for legacy/existing projects, and that's the hole Type-C plugs. Imagine a legacy embedded FreeRTOS or RTEMS or Zephyr codebase with existing tooling where you want to introduce a little be of patter matching convenience and type safety? With Type-C you would just rename one of the files to .tc, use whatever features you need, add a new .tc rule to the Makefile and that's it. Everything else will work as it did, with the same compiler, tooling and so on. No new compiler, runtime or having to convince coworkers to switch to a new language.

For some still widely used architectures, like SH4, there isn't even Clang compiler yet, let alone Rust or Ocaml. So you need C.

This is the use case Type-C targets.

1 comments

The alternative would be a C generation backend, like many toolchains offer for such scenarios.
Which language toolchains offer that? As far as I know for most it results in a multiple C files, foreign interfaces due to different ABIs and a runtime library on top.
So the point is that it is available, or not?

Eiffel being one, Nim, several Scheme compilers, MLton, F*, KreMLin, Koka, Rust (rustc_codegen_c),...