On Tue, Oct 12, 1999 at 02:50:33 -0700, Simon Peyton-Jones wrote:
[non-H98 compliant version]
>> That's of course exactly what one wants to write, but AFAIK this is not
>> Haskell 98, so I wanted to avoid it. Or is it Haskell 98? %-}
> It's not H98, but you could instead write
> instance Marshalable a => Marshalable (Vec3 a) where
> indexOffAddr buf off = do
> let sizeOfPolymorphicA = sizeOf (indexOffAddr buf 0)
> ...
> Pretty wierd, but it should work.
Second try... should now be H98 compliant & not-so-weird... ;-)
\begin{code}
instance Marshalable a => Marshalable (Vec3 a) where
indexOffAddr buf off =
let [x, y, z] = map (indexOffAddr buf) [off, off + soPA, off + 2*soPA]
soPA = sizeOf x
in Vec3 x y z
readOffAddr buf off = do
x <- readOffAddr buf off
let soPA = sizeOf x
[y, z] <- mapM (readOffAddr buf) [off + soPA, off + 2*soPA]
return $ Vec3 x y z
...
\end{code}
Cheers,
Michael
--
"Hi, I'm new at Alpha..this might sound dumb even..
Can I install Windows 95/98 on Dec Alpha machine?"
-- Brian Seo in comp.os.linux.alpha