When generating C (using the `-fvia-C' directive), one can assist the C compiler in detecting type errors by using the `-#include' directive to provide `.h' files containing function headers.
typedef unsigned long *StgMallocPtr; typedef long StgInt; extern void initialiseEFS PROTO( (StgInt size) ); extern StgInt terminateEFS (); extern StgMallocPtr emptyEFS(); extern StgMallocPtr updateEFS PROTO( (StgMallocPtr a, StgInt i, StgInt x) ); extern StgInt lookupEFS PROTO( (StgMallocPtr a, StgInt i) );
You can find appropriate definitions for `StgInt', `StgMallocPtr', etc using `gcc' on your architecture by consulting `ghc/includes/StgTypes.lh'. The following table summarises the relationship between Haskell types and C types.
C type name Haskell Type ----------------------------------------------------- `StgChar' `Char#' `StgInt' `Int#' `StgWord' `Word#' `StgAddr' `Addr#' `StgFloat' `Float#' `StgDouble' `Double#' `StgArray' `Array#' `StgByteArray' `ByteArray#' `StgArray' `MutableArray#' `StgByteArray' `MutableByteArray#' `StgStablePtr' `StablePtr#' `StgMallocPtr' `MallocPtr#'
Note that this approach is only essential for returning `float's (or if `sizeof(int) != sizeof(int *)' on your architecture) but is a Good Thing for anyone who cares about writing solid code. You're crazy not to do it.