[Haskell-cafe] Re: Using of C constants in Haskell sources; Determining compilation environment (Unix vs Windows)

Max Vasin max.vasin at gmail.com
Tue Jul 11 12:53:11 EDT 2006


>>>>> "Bulat" == Bulat Ziganshin <bulat.ziganshin at gmail.com> writes:

Bulat> Hello Haskell, what is a best way to bring C constant (defined
Bulat> in header file) into the Haskell source? Haskell project is
Bulat> cabalized and should work with both Win and Unix while the
Bulat> constants are OS-specific. the best way i found at this moment
Bulat> is to use the following scheme:

Bulat> mmap.h:

Bulat> #if defined(mingw32_HOST_OS) || defined(__MINGW32__) ||
Bulat> defined(_MSC_VER) ....  #else INLINE int const_MAP_FILE( void )
Bulat> { return MAP_FILE;
Bulat> }
Bulat> #endif

Bulat> mmap.hs:

Bulat> #if defined(mingw32_HOST_OS) || defined(__MINGW32__) ||
Bulat> defined(_MSC_VER) ....  #else foreign import ccall unsafe
Bulat> "mydefs.h const_MAP_FILE" mAP_FILE :: CInt #endif

Well, the haskell source is processed with cpp, so if constants
are #define'd (and not declared with `const') you can use preprocessor
macros to generate Haskell code (yeh, I know it's silly, but why not?).

-- 
WBR,
Max Vasin.

NP: Nothing playing right now



More information about the Haskell-Cafe mailing list