[C2hs] timespec and c2hs

Erik Hesselink hesselink at gmail.com
Sat Dec 11 16:23:05 CET 2010


Hi,

I'm trying to write a Storable instance for timespec using c2hs. Since
timespec is defined something like:

struct timespec {
  time_t tv_sec;
  long tv_nsec;
};

I've defined the following in Haskell:

#include <sys/time.h>

#c
typedef struct timespec timespec_t;
#endc

data TimeSpec = TimeSpec
  { seconds :: CTime
  , nanoseconds :: CLong
  }

instance Storable TimeSpec where
  peek t = TimeSpec <$> {#get timespec_t->tv_sec #} t <*> {#get
timespec_t->tv_nsec#} t
  ...

However, this fails to compile. For tv_sec, c2hs generates
"peekByteOff ptr 0 :: IO CLong" instead of "IO CTime". Why is this? Am
I doing something wrong, or is there a bug/missing feature in c2hs?

Erik



More information about the C2hs mailing list