Simon Marlow wrote:
> I don't think it's going to return, but if there is something you
> rely on from it, then we should attempt to support it in the new FFI
> story. [...]
The recent thread on binary IO almost included showBytes (in my
proposal for hPutBin):
-------------------------------------------------------------------
type Bytes = [Char]
-- The code below is the same as
-- (unsafePerformIO (inParam (unmarshalList (sizeOf x)) x) ++)
-- unfolded.
showBytes :: Storable a => a -> Bytes -> Bytes
showBytes x xs = unsafePerformIO $ do
buf <- mallocElem x
poke buf x
val <- mapM (peekElemOff buf) [ 0 .. sizeOf x - 1 ]
free buf
return (val ++ xs)
{- Even more imperative, but without ++ :-P
showBytes :: Storable a => a -> Bytes -> Bytes
showBytes x xs = unsafePerformIO $ do
buf <- mallocElem x
poke buf x
let s = sizeOf x
loop i cs | i == s = return cs
| otherwise = do c <- peekElemOff buf i
loop (i+1) (c:cs)
val <- loop 0 xs
free buf
return val
-}
-------------------------------------------------------------------
Cheers,
Sven
--
Sven Panne Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen Oettingenstr. 67
mailto:[EMAIL PROTECTED] D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne