Better HN
topnewbestaskshowjobs
Log inSign up

stass

463 karma · joined Feb 14, 2009 (17y ago) · 195 submissions

Aspiring programmer.
Submissions

comment 15h ago · link · parent

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.

comment 15h ago · link · parent

Debatable.

comment 15h ago · link · parent

> Why C11? We're in 2026, we should target C23 at least, with a forward look at C2y.

Mostly compiler support. I wanted for it to work with a wide range of compilers, so didn't want to introduce a dependency on C23 or beyond. Having said that, I expect Type-C to any C23 code as well, but I haven't systematically tested that.

Basically it's designed to support any somewhat recent random ass compiler as a backend, like GCC for SH4.

> Why the keyword "type"? Can't the same functionality be added within a typedef statement?

This would be tricky. In C typedef creates an alias for an existing type, not a new type, so overloading typedef would make it mean two different things depending on the context. A more technical reason is that typedef puts the new name last where is Type-C needs it come first so it can be used in recursive types like e.g. "type expr = | Num(long v) | Add(expr l, expr r)". This is the reason C itself needs forward declaration for structs for recursive types.

A new keyword, type, costs nothing as Type-C only recognizes it at the beginning of declarations which is not a valid C anyway.

> Is there a reason why "|" can't be recognized wherever a type is expected?

It can, but that would be challenging and ROI is unclear. Right now variant types are nominal, so the same "A(int)|B" type in two places will be treated as two separate types. Making variant types structural, especially across multiple .tc modules, is... not even sure it's even possible to build the way Type-C is built. C code Type-C generates also needs a name for the C type and currently that comes from the declared Type-C type. Anonymous types will need a stable name across interfaces, so typec compiler will need to parse the entire codebase or become a standalone compiler instead of emitting C.

> And finally, the name "Type-C"... Isn't it already closely associated with USB connectors?

It came from TypeScript as it's a TypeScript idea applied to C. And having it sound like a Type-C connector seemed like a fun pun.

comment 15h ago · link · parent

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.

comment 17h ago · link · parent

What are the core issues? Some of the C pains are hard to solve without breaking the language.

comment 19h ago · link · parent

Just checked spy-ast, it looks cool! I like how it's trying to approach the same problem from a different angle for a dynamically typed language.

I picked OCaml vs vlang mostly because I'm more familiar with it and it's so well suited for parsers/compilers with its ADTs and pattern matching -- ironically the same features I wanted to add to C. It has a great ecosystem of existing tools and packages as well and cross-platform support, which is good for portability.

comment 19h ago · link · parent

My list of other languages was not exhaustive, just like C++ matches. :-D

On a serious note, it's a fair point: it does have std::variant, std::visit and std::expected in C++23, but the do force you to embrace C++ verboseness: e.g. you have to write a per-case visitor for std::visit compile-time check. It also still lacks exhaustive matching, distinct types, and has a different ABI from C.

I felt like Swift/OCaml were closer in spirit to what I was trying to achieve in Type-C.

comment 2d ago · link · parent

Realized that the post is a bit light on numbers, so here're some.

I rewrote the parser of tomlc99 (2k lines) in Type-C as a test. I used result/try/defer for the error paths and left everything else unchanged, linking against the same C programs and tests.

Doing fault injection with one failed allocation per run over ~1500 runs: the original C went wrong in 34 (25 leaks, 9 use-after-free); the rewrite went wrong never, sanitizers clean.

With original toml-spec-tests files: the original leaked in 1002 of them and crashed in 9; the rewrite did neither.

This is an example of how the code looks like for an expression evaluator: type expr = | Num(int value) | Add(const expr l, const expr r) | Mul(const expr l, const expr r) | Div(const expr l, const expr r);

  static result(int, eval_error)
  eval(const expr *e)
  {
      int d;

      match (*e) {
      case Num(value):
          return (Ok(value));
      case Add(l, r):
          return (fit((long long)try eval(l) + try eval(r)));
 …
Happy to answer any questions!

9.

Show HN: Type-C – variants, options, generics and pattern matching for C(github.com ↗)

48 points · by stass · 2d ago · 22 comments

comment 4d ago · link · parent

Yes, the OS is based on the capability microkernel so processes are only allowed to do things explicitly granted to them. Network access is an explicit capability and can be broken down further by protocol/port/traffic etc.

I haven’t looked into more granular capabilities like granting access to specific sites yet, but this should be pretty easy to implement as the OS network server is itself in erlang, and all network request go through it.

11.

Show HN: erXos – a microkernel OS in Erlang based on Genera/Plan 9/QNX ideas(stass.github.io ↗)

11 points · by stass · 4d ago · 3 comments

12.

Show HN: AWKLog – a minimalist Datalog interpreter in Awk(github.com ↗)

4 points · by stass · 3w ago · discuss

comment 1y ago · link · parent

I cheated a little bit and don't calculate the fluid dynamics in real time. Instead, I'm using force models from the excellent Aero-Hydrodynamics of Sailing book by Marchaj, which is sadly out of print. I then do iterative balancing of the drag force and combined drag/lift forces on sails until they converge.

comment 1y ago · link · parent

SailRhythm is a bit WIP, so didn't want to share too early!

Thank you so much for the detailed feedback. I do have plans to implement wind flow visualization and have a way to visualize forces as well. Controls a bit tricky to do, but this is definitely something I've been pondering. As you said, at certain headings the changes sometimes are too small to perceive.

comment 1y ago · link · parent

You get water graphics for free from three.js

comment 1y ago · link · parent

If other people are interested in sailboat physics -- this resource is a goldmine of information on how sailboat and sails work and physics around it: https://www.onemetre.net/Design/Design.htm

comment 1y ago · link · parent

Please!

comment 1y ago · link · parent

Definitely recommend taking an introductory ASA 101/102/103 classes from a local school! Will help you decide if you are into it while having some fun.

This is how I started.

comment 1y ago · link · parent

I built one recently to mostly help myself visualize how sail trim worked and how various boat controls like mainsheet and backstay affected sail shapes, various forces and boat performance. It uses a physics-based VPP and I calibrated it against Catalina 36 polar charts, so should be pretty precise!

I plan to integrate the simulator with the sail trim guide I'm building to help people learn.

It's a WIP, but accessible at https://www.sailrhythm.com/

Happy to answer any questions!

comment 1y ago · link · parent

There is a great school called Modern Sailing School in Sausalito. I highly recommend taking a class from them. I took one in the past and they are great!

Will help you figure out if you are into sailing or not.

comment 1y ago · link · parent

Not my demo! But I got inspired by it some time ago to build a simulator for monohulls which uses a physics based VPP to calculate the boat speed based on input controls like mainsheet, jib sheet, travelers, backstay and so on at https://www.sailrhythm.com/

It uses Catalina 36 Tall Rig as a base model for sailboat parameters and was calibrated to match ORC-published polars for it within 1-5% on both close, beam and broad reaches.

Mostly built it for myself to help me understand how less common control affect the sail shapes, angles of attack and boat heel and behavior in a visual way.

It's still WIP, but you might find it useful for yacht-specific stuff!

22.

Sail-Trim Simulator(simulator.atterwind.info ↗)

140 points · by stass · 1y ago · 28 comments

comment 1y ago · link · parent

Even still a lot of information is not online. I've been building a web sail trim simulator and had to hunt down a physical copy of the Aero-Hydrodynamics of Sailing book by Marchaj, because a lot of the formulas and models I needed to simulate the boat were not online, and what was online was often wrong.

comment 1y ago · link · parent

This site is an absolute treasure trove of technical material on sail and hull design, with a focus on model yachts but most of the physics scales up. It covers aerofoil theory (momentum, circulation, lifting line), sail twist, downwash, planform effects, Reynolds number, hull resistance, appendage design, VMG, and more.

Lots of spreadsheets and practical calculators too—bulb shape optimization, wetted surface area, simple VPP models. If you're into sail performance modeling or yacht design, this is one of the best resources out there.

25.

How a yacht works: sailboat physics and design(onemetre.net ↗)

254 points · by stass · 1y ago · 76 comments

comment 1y ago · link · parent

You can now automatically debug native apps from Claude or Cursor using LLDB.

Here it is automatically analyzing buffer overflow in a binary: https://x.com/full_duplex/status/1904770477698277847

27.

MCP Server for LLDB(github.com ↗)

3 points · by stass · 1y ago · 1 comment

comment 2y ago · link · parent

Does this somehow disqualifies SpaceX as a contract supplier?
1234567