3 ms·
Haskell: It is implemented as a library, without needing compiler support [*]. You can write C++ in TemplateHaskell (Haskell's strongly typed AST-generating m
by nh2 3y ago
Haskell:
It is implemented as a library, without needing compiler support [*].
You can write C++ in TemplateHaskell (Haskell's strongly typed AST-generating macro system), which allows you to use Haskell variables in scope inside your C++ functions.
The "inline-c" library allows this for C and C++.
Example of its use in the Haskell OpenCV bindings: https://hackage.haskell.org/package/opencv-0.0.2.1/docs/src/OpenCV-Features2d.html#orbDetectAndCompute https://hackage.haskell.org/package/opencv-0.0.2.1/docs/src/...
The way it works: It invokes the C++ compiler for you to generate a wrapper function that closes over the Haskell variables used in your code snippet, and on the Haskell side generates a corresponding type-safe function call for you.
This approach allows you to use all C++ features that a C++ compiler supports.
But it also carries the drawback of ... invoking a C++ compiler, which gives you the slow build speed of C++.
[*] Some compiler support was added to be able to specify compiler flags that are specific to the C++ compiler but not the C compiler.
- gpderetta 3y agoLove the non-standard formatting :). It took me a while to see where haskell ended and C++ started. Seems very powerful.