Hi,
        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


On the other hand, if I replace 'with' with 'with1':

with1 :: (Storable a) => a -> ( Ptr a -> IO b ) -> IO b
with1 x f = do p <- mallocBytes (sizeOf x)
               let p'=castPtr p :: Ptr a
               poke p' x
               y <- f p'
               free p
               return y

it seems to work. I could not even get to work 'malloc :: IO (Ptr
(Int,Int))', while 'malloc :: IO (Ptr Int)' works fine.
Am I doing something wrong, or is there a bug in
the library code?

Yours,

Jan


-- 
-------------------------------------------------------------------------
Jan Kybic <[EMAIL PROTECTED]>      Odyssee, INRIA, Sophia-Antipolis, France
       or <[EMAIL PROTECTED]>,tel. work +33 492 38 7589, fax 7845
             http://www-sop.inria.fr/odyssee/team/Jan.Kybic/index.en.html
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to