GHC 5.02 and Word8 
Author Message
 GHC 5.02 and Word8

Hi,

Please can someone explain how I get Word8 on GHC 5.02 (the version
that comes with Debian).

I've tried various combinations of -fglasgow-exts, import Word and
import Word8.  I can't find a clear description in the docs.

Even better, if someone could point me to some example code that does
binary IO (I understand I need to use Word8 and some kind of Array
associated with the IO Monad).

Assorted error messages below for your delight.

Thanks,
Andrew


Pancito3.lhs:20:
    failed to load interface for `Word':
        Could not find interface file for `Word'

Pancito3.lhs:20:
    failed to load interface for `Word8':
        Could not find interface file for `Word8'

Pancito3.lhs:262: Type constructor or class not in scope: `Word8'

Glasgow Haskell Compiler, Version 5.02.2, for Haskell 98, compiled by
GHC version 5.02.2



Thu, 27 Oct 2005 11:43:59 GMT  
 GHC 5.02 and Word8
andrew cooke napisa3:

Quote:
> Hi,

> Please can someone explain how I get Word8 on GHC 5.02 (the version
> that comes with Debian).

> I've tried various combinations of -fglasgow-exts, import Word and
> import Word8.  I can't find a clear description in the docs.

Try
    import Data.Word
or
    import Word
    (and compile with -package data)

Best regards,
Tom

--
.signature: Too many levels of symbolic links



Thu, 27 Oct 2005 16:12:14 GMT  
 GHC 5.02 and Word8

Quote:

> Even better, if someone could point me to some example code that does
> binary IO (I understand I need to use Word8 and some kind of Array
> associated with the IO Monad).

Here's one way to do it. The core is the polymorphic function hGet,
which will read any instance of Storable. The rest of the code is just
type coercion.

Quote:
> import IO
> import Char
> import Word
> import Int
> import Foreign.Ptr
> import Foreign.Storable
> import Foreign.Marshal.Alloc

> --

> fromOctets :: Storable a => [Word8] -> IO a
> fromOctets xs = do
>    alloca $ \ptr -> do
>            let bptr = castPtr ptr :: Ptr Word8
>            sequence_ [pokeElemOff bptr i x | (i, x) <- zip [0..] xs]
>            x <- peek ptr
>            return x

> charToOctet :: Char -> Word8
> charToOctet c = fromIntegral (ord c)

> --

> hGet :: Storable a => Handle -> a -> IO a
> hGet handle dummy = do
>    let n = sizeOf dummy
>    cs <- mapM (const $ hGetChar handle) [1..n]
>    let bs = map charToOctet cs
>    result <- fromOctets bs
>    return result

> --

> hGetNum :: (Storable a, Num a) => Handle -> IO a
> hGetNum handle = hGet handle 0

> --

> hGetByte :: Handle -> IO Word8
> hGetByte handle = hGetNum handle

> hGetWord :: Handle -> IO Word16
> hGetWord handle = hGetNum handle

> hGetShort :: Handle -> IO Int16
> hGetShort handle = hGetNum handle

> hGetInt32 :: Handle -> IO Int32
> hGetInt32 handle = hGetNum handle

> hGetInt :: Handle -> IO Int
> hGetInt handle = hGetInt32 handle >>= return . fromIntegral

> hGetFloat :: Handle -> IO Float
> hGetFloat handle = hGetNum handle

> hGetDouble :: Handle -> IO Double
> hGetDouble handle = hGetNum handle

--



Sat, 29 Oct 2005 12:27:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. WIN ME and CLIPPER 5.02

2. Probs with 5.2d (Update from 5.02)

3. Sharing violation - Clipper 5.02 app under Win95

4. LavVIEW 5.02 patch

5. About Snap 5.02

6. TASM 5.0 with BC++ 5.02 ?

7. BC++ 5.02 and Tasm32.exe....

8. How to embed Python with Borland C++ 5.02?

9. GCL 2.2.2 and CLX 5.02 Problems

10. TCL 8.* compiled with Borland 5.02

11. Compiling Tk8.0 with Borlands C++ 5.02

12. COM error with Word8

 

 
Powered by phpBB® Forum Software