After fiddling around a little bit I think that there is room for
even more unification. The Foreign module exports some functions
quite similar to those exported from Addr, so here is my next
proposal:
----------------------------------------------------------------------
class MemInfo a where
sizeOf :: a -> Int
alignment :: a -> Int
class MemInfo b => Marshalable a b where
indexOff :: a -> Int -> b
readOff :: a -> Int -> IO b
writeOff :: a -> Int -> b -> IO ()
----------------------------------------------------------------------
-- Example: Char instances
instance MemInfo Char where
sizeOf = const 1 -- determined by autoconf/configure
alignment = const 1 -- determined by autoconf/configure
instance Marshalable Addr Char where
indexOff = indexCharOffAddr
readOff = readCharOffAddr
writeOff = writeCharOffAddr
instance Marshalable ForeignObj Char where
indexOff = indexCharOffForeignObj
readOff = readCharOffForeignObj
writeOff = writeCharOffForeignObj
----------------------------------------------------------------------
Two remarks:
* I'm not quite happy with the name "MemInfo", but didn't have a
a better idea.
* Are MPTC really needed here or is there a better/easier way to
organize the above methods into classes?
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