Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Poica – Algebraic data types and type introspection for pure C (github.com/hirrolot)
116 points by hirrolot on June 18, 2020 | hide | past | favorite | 8 comments



This is ... wild. Usually these things explode in size when compiled, require an external preprocessor, and/or heavily lean on system calls. This does none of those things.


Doesn't this require an external preprocessor? The Boost Preprocessor


No, boost/preprocessor is a library that offers metaprogramming primitives for the standard C/C++ preprocessor


Neat. I wrote a similar header only library a long time ago just for sum types, so it's a little more limited but works for C89 or later IIRC:

https://github.com/naasking/libsum


Unfortunately none of the examples contain malloc, whilst I'm curious as to whether the pattern matching works with heap allocated object. The binary tree example only has statically defined tree, which blows up into lots of code in assembly.


So in this case the connection to algebraic data types is that they provide static type checking for unions as well as structs in C along with type introspection which is novel.

The linked article explaining the whys and wherefores of ADTs (https://codewords.recurse.com/issues/three/algebra-and-calcu...) has hit the front page of HN twice now!


I wonder whether this interacts cleanly with Cello, GTK+, or other "object-oriented" C libraries. It certainly is a nice presentation, if a little baroque.


wow that actually looks pretty clean




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: