3 ms·
Many languages — Haskell included — can compile to C. Compiling down to C and then piggybacking off the system C compiler is a fairly common way of getting a so
by chc 14y ago
Many languages — Haskell included — can compile to C. Compiling down to C and then piggybacking off the system C compiler is a fairly common way of getting a sophisticated native codegen without needing to implement one yourself. But simply compiling down to C doesn't necessarily put the language in the same relationship with C that CoffeeScript is with JavaScript.
To be honest, I could imagine a slightly nicer skin over C, but C is already a pretty good C. Any "CoffeeScript for C" would probably work out to a poor reimplementation of an early C++ compiler with the semicolons removed.
- tikhonj 14y agoThis isn't compiling Haskell down to C. It's using a DSL to generate C. The DSL just happens to be embedded in Haskell. Haskell is just an environment, a language factory. Haskell is used for creating the abstractions and meta-programming. You can also piggy back on Haskell's type system to enforce certain invariants. But ultimately the semantics of the DSL--what actually gets turned into C--are not necessarily related to Haskell at all. Instead, the semantics are tailored for your particular application. In the particular case of atom, this application is hard real-time programming. Another example is something one of my friends worked on in OCaml. He essentially created a little algebraic system which provided all the operations for a field (with maybe a couple other ones). This is enough to implement a bunch of variations on a Kalman filter. He could then iterate quickly and test the code locally; when he was content, he could use the same code to output abstraction-free C which he could then compile and deploy on ARM. The point being that the host language is not related to C; it's the embedded DSL that plays the role of CoffeeScript. (Although any reasonable DSL would be quite a larger departure from C than CoffeeScript is from JavaScript.) You just use Haskell/OCaml/Scala/whatever to save having to implement a parser, type system and so on.
- steveklabnik 14y agoI thought `-f-via-c` was removed long ago.
- chc 14y agoAFAIK it isn't removed, but it is no longer developed and requires GHC to be in unregistered mode, which most people's won't be. But I could simply be behind the times.
- steveklabnik 14y agoLooking into it, we're both right, in a way: > This is the oldest code generator in GHC and is generally not included any > more having been deprecated around GHC 7.0. Select it with the -fvia-C flag. So it was deprecated, just never removed.