3 ms·
Using Haskell’s ‘newtype’ in C
- jrockway 16y agoYes, very nice. What I've learned about C recently is that while the default language and standard library has no type safety and is generally horrible, it has all the tools you need to build something that is type safe and not horrible. And, most of the time, it doesn't even incur a speed hit. Now I just need to teach the people writing 99% of the C programs I encounter to not do it so horribly :)
- barrkel 16y agoIt only has such tools in so far as you can use macros to translate non-horrific syntax into something intelligible to the type system, which can in turn give meaningful diagnostics. It's still hard to create e.g. even simple value-oriented safe string semantics that don't bleed parentheses all over the screen in function or macro invocations.
- ay 16y agoI think it may be worth mentioning that an excessively passionate romance with macros may backfire at debugging time. A crash in a code that is created by a macro expanded into a several thousand characters line is quite not easy to explore in gdb.