I'm building a small haste project where I want to use Elasticsearch. However, bloodhound which seems like the library to go for for elasticsearch in haskell depends indirectly on template-haskell - which isn't supported by haste. Now, I don't need to call elastic from the client, so I don't need bloodhound in haste, but I need to be able to call it from within the same code base as haste is built to use the same code for server and client side. I guess I somehow could have separate client and server side implementations but I really like the haste way.
How can I have calls to dependencies that only exist on the server side in haste?
Preprocessor can be used for this purpose. Haste defines
__HASTE__macro so it should be enough to wrap your code in conditional statement:Don’t forget to enable C preprocessor extension using
{-# LANGUAGE CPP #-}pragma.You can also achieve similar effect in your ‘.cabal’ file:
(source https://github.com/valderman/haste-compiler/blob/0.4/libraries/haste-lib/haste-lib.cabal#L63)
Note that the
haste-instflag has been renamed tohaste-cabalin the latest development version of Haste.