> I am using ghc-5.04 and a code like: > > with c ( \c' -> hPutBuf h c' (sizeOf c)) > > fails with "Fail: Prelude.undefined" when "c" is a user defined type, > such as a pair: > > instance (Storable at,Storable bt) => Storable (at,bt) where > sizeOf (a,b) = sizeOf a + sizeOf b > alignment (a,b) = max (alignment a) (alignment b) > peek p = do a <- peek ((castPtr p):: Ptr at) > b <- peekByteOff ((castPtr p):: Ptr bt) (sizeOf a) > return (a,b) > poke p (a,b) = do poke ((castPtr p):: Ptr at) a > pokeByteOff ((castPtr p):: Ptr bt) > (sizeOf a) b
sizeOf and alignment are not supposed to evaluate their arguments. You might try making the definitions in your instance above a little lazier: sizeOf z = sizeOf a + sizeOf b where (a,b) = z alignment z = max (alignment a) (alignment b) where (a,b) = z (feel free to use '~' if you prefer). Cheers, Simon _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell