Ross Paterson | 8 Aug 2002 08:31
Picon
Favicon

haskell98 modules

haskell98/IO.hs should also hide hTell, hSetEcho, hGetEcho and
hIsTerminalDevice.  On the other hand, perhaps it would be better to
just copy the export lists for these modules from the library report,
so the underlying modules can export more stuff without affecting them.
Ashley Yakeley | 21 Aug 2002 06:55

Word8-Based IO

Was there any kind of consensus emerging on this? Leaving aside what 
might be done with the Char-based functions (and people seem to think 
they're fine as is) I'd like to suggest the following:

* System.IO: addition of new Word8-based functions

  hGetOctet :: Handle -> IO Word8
  hLookAheadOctet :: Handle -> IO Word8
  hPutOctet :: Handle -> Word8 -> IO ()
  hPutArray :: Handle -> [Word8] -> IO ()
  hLazyGetArray :: Handle -> IO [Word8]

...as per hGetChar, hLookAhead, hPutChar, hPutStr and hGetContents.

  hGetArrayBlock :: Handle -> Int -> IO [Word8]
  hGetArrayReady :: Handle -> Int -> IO [Word8]

hGetArrayBlock would read so many octets from the handle, up to the EOF.
hGetArrayReady would read so many octets from the handle, up to the EOF 
or octets not ready. The semantics would be something like this:

  hGetArrayBlock h 0 = return [];
  hGetArrayBlock h n = do {
      eof <- hIsEOF h;
      if eof then return [] else do {
          first <- hGetOctet;
          rest <- hGetArrayBlock h (n - 1);
          return (first:rest);
      };
  };
(Continue reading)

Ketil Z. Malde | 21 Aug 2002 09:52
Picon
Picon

Re: Word8-Based IO

Ashley Yakeley <ashley <at> semantic.org> writes:

> Was there any kind of consensus emerging on this?

I think we agreed, more or less, on low-level Word8-based IO, and Char
based functions on top of this doing encoding/decoding.  (Possibly
implementing Char functions natively for speed, but I suggest delaying
that until it becomes a problem)

> Leaving aside what might be done with the Char-based functions (and
> people seem to think they're fine as is) 

Well, clearly, they need to be able to incorporate the encodings
people are going to use.  Just stuffing in Word8's works fine for now,
but we should probably reimplement in terms of Word8 IO, and after
that, wrap at least an UTF-8 coder.  (I occasionally need something
to translate UTF-8 mail to ISO-8859-1, this sounds like a simple way
to get a feel for Unicode IO, and is probably a good alternative to
upgrading Gnus :-) 

> I'd like to suggest the following: 

> * System.IO: addition of new Word8-based functions
> 
>   hGetOctet :: Handle -> IO Word8
>   hLookAheadOctet :: Handle -> IO Word8
>   hPutOctet :: Handle -> Word8 -> IO ()
>   hPutArray :: Handle -> [Word8] -> IO ()
>   hLazyGetArray :: Handle -> IO [Word8]
> 
(Continue reading)

Simon Marlow | 21 Aug 2002 11:34
Picon
Favicon

RE: Word8-Based IO


> Was there any kind of consensus emerging on this? Leaving aside what 
> might be done with the Char-based functions (and people seem to think 
> they're fine as is) I'd like to suggest the following:
> 
> * System.IO: addition of new Word8-based functions
> 
>   hGetOctet :: Handle -> IO Word8
>   hLookAheadOctet :: Handle -> IO Word8
>   hPutOctet :: Handle -> Word8 -> IO ()

I'd go for hGetWord8, hLookAheadWord8 and so on, but it's not a big
deal.

>   hPutArray :: Handle -> [Word8] -> IO ()

There are currently these two functions in Data.Array.IO:

  hGetArray :: Handle -> IOUArray Int Word8 -> Int -> IO Int 
  hPutArray :: Handle -> IOUArray Int Word8 -> Int -> IO () 

turning an IOUArray Int Word8 into [Word8] is accomplished by
Data.Array.IArray.elems.

>   hLazyGetArray :: Handle -> IO [Word8]

Other suggestions: hGetContentsRaw, hGetWord8Contents

> ...as per hGetChar, hLookAhead, hPutChar, hPutStr and hGetContents.
> 
(Continue reading)

Ashley Yakeley | 22 Aug 2002 11:34

RE: Word8-Based IO

At 2002-08-21 02:34, Simon Marlow wrote:

>I'd go for hGetWord8, hLookAheadWord8 and so on, but it's not a big
>deal.

Yeah you're right. Plus I got confused with lists and arrays.

>>   hLazyGetArray :: Handle -> IO [Word8]
>
>Other suggestions: hGetContentsRaw, hGetWord8Contents

hGetContents is the only lazy IO function isn't it? I don't really 
approve of lazy IO and I was hoping to stigmatise the name with "lazy" 
much as the unsafe functions have "unsafe".

--

-- 
Ashley Yakeley, Seattle WA
Simon Marlow | 22 Aug 2002 11:54
Picon
Favicon

RE: Word8-Based IO


> At 2002-08-21 02:34, Simon Marlow wrote:
> 
> >I'd go for hGetWord8, hLookAheadWord8 and so on, but it's not a big
> >deal.
> 
> Yeah you're right. Plus I got confused with lists and arrays.
> 
> >>   hLazyGetArray :: Handle -> IO [Word8]
> >
> >Other suggestions: hGetContentsRaw, hGetWord8Contents
> 
> hGetContents is the only lazy IO function isn't it? I don't really 
> approve of lazy IO and I was hoping to stigmatise the name 
> with "lazy" much as the unsafe functions have "unsafe".

hGetContents, getContents, and readFile are the lazy functions.
Actually I think lazy I/O is highly unsavoury myself, but I'm guessing
there would be strong opposition to changing these names to include the
word "lazy".

Cheers,
	Simon
Volker Stolz | 28 Aug 2002 16:38

Adding repeatM / repeatM_ to Control.Monad

Are there any objections to adding abbreviations for 
   repeatM = sequence.replicate 
and 
   repeatM_ = sequence_.replicate
to Control.Monad? I think they are convenient in the same way many
others are.

Volker
--

-- 
http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME
Dean Herington | 28 Aug 2002 19:07
Picon
Favicon

Re: Adding repeatM / repeatM_ to Control.Monad

Wouldn't `replicateM` and `replicateM_` be more appropriate names?

Dean

On Wed, 28 Aug 2002, Volker Stolz wrote:

> Are there any objections to adding abbreviations for 
>    repeatM = sequence.replicate 
> and 
>    repeatM_ = sequence_.replicate
> to Control.Monad? I think they are convenient in the same way many
> others are.
> 
> Volker
> -- 
> http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME
Volker Stolz | 28 Aug 2002 19:11

Re: Adding repeatM / repeatM_ to Control.Monad

On Wed, Aug 28, 2002 at 01:07:51PM -0400, Dean Herington wrote:
> Wouldn't `replicateM` and `replicateM_` be more appropriate names?

You're right, that's what I've got in my private library, too.
I just didn't type what was in my head.
--

-- 
Volker Stolz * stolz <at> i2.informatik.rwth-aachen.de * PGP + S/MIME 
Volker Stolz | 29 Aug 2002 10:12

Re: Adding replicateM / replicateM_ to Control.Monad

The following is what I intend to commit. There's a gratuitious
foldM_ as well.

Index: Control/Monad.hs
===================================================================
RCS file: /home/cvs/root/fptools/libraries/base/Control/Monad.hs,v
retrieving revision 1.5
diff -r1.5 Monad.hs
29a30
>     , foldM_        -- :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
43a45,46
>     , replicateM    -- :: (Monad m) => Int -> m a -> m [a]
>     , replicateM_   -- :: (Monad m) => Int -> m a -> m ()
139a143,151
> 
> foldM_            :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
> foldM_ f a xs     = foldM f a xs >> return ()
> 
> replicateM        :: (Monad m) => Int -> m a -> m [a]
> replicateM n x    = sequence (replicate n x)
> 
> replicateM_       :: (Monad m) => Int -> m a -> m ()
> replicateM_ n x   = sequence_ (replicate n x)
--

-- 
plonk :: m a -> m ()
http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME

Gmane