Show HN: Type-C – variants, options, generics and pattern matching for C github....
HN Best 200 @best
Show HN: Type-C – variants, options, generics and pattern matching for C github.com · 8 points · 0 comments · HN thread
TL;DR Type-C is a preprocessor-style superset of C11 that adds closed variants with exhaustive match, distinct types, generic types, option and result with try, and defer. Its compiler typec translates .tc files into plain C and hands that C to GCC or Clang, so adopting it can be done one file at a time. The language is described as version 1.0 with a checked mode still designed but not built; the thread has no comments yet.
- Variants are closed sums; match must cover every constructor, so a missing case stops the build with error [match-coverage].
- distinct types (e.g. user_id vs group_id) refuse implicit conversion, catching swapped arguments that a C typedef would silently accept.
- Generic types such as list(T), option(T) and result(T, E) are supported, with try returning errors early and defer running cleanups at every exit.
- typec writes C, with no runtime or added link dependency; the author reports the tomlc99 rewrite adds 2.8% to 11.9% object size and no measurable parse-time cost.
- A C11 file is valid Type-C, so an existing .c file can be renamed to .tc and built with CC=typec alongside the rest of the project; Makefile, Ninja and CMake rules are shown.
- Not yet implemented: checked mode for memory safety, which the author lists as designed but unbuilt work.
Discussion No comments have been posted yet, so there is no discussion to summarize.
#C #compilers #patternmatching #programminglanguages #preprocessor #ShowHN