Proposal: Add concatMapM function (#2042)

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Feb 1 06:25:52 EST 2008


Hello Ketil,

Friday, February 1, 2008, 10:52:02 AM, you wrote:

>> f <- openFile "name" >>= withLocking >>= withEncoding utf8

> Attaching modifiers to handles appears to solve the problem of
> retaining 100% backwards compatibility, while opening for dealing with
> modern character sets.

may be it's too draconian restriction but i proposed just to use new
library in the new code. we can provide easy way to switch from
Handles by providing emulation module System.Stream.IO which exports
things with the old names - Handle, hGetContents... - but new
implementation

> Somebody raised the question of reading a Content-type field, etc:
> would it be possible to "rewind" a handle after setting encoding?  For
> Content-type fields, I suspect the header is usually limited to ASCII
> anyway, so adding decoding for subsequent text is probably
> sufficient.  But how about a 'withDefaultEncoding' modifier that
> inspects the first two (or four?) bytes for a Unicode BOM, and either
> sets decoding accordingly and continues, or sets encoding according
> to locale *and* lets the user read the first bytes when reading from
> the handle.

core of my library is *interfaces*, not implementations. openFile
provides a getByte/putByte interfaces and also trivial getChar/putChar
which just reads/writes one byte. withEncoding modifier provides
another getChar/putChar implementations what process several bytes at
once. you can dress file to one or another modifier at any moment, its
internal read/write pointer isn't affected:

f <- openFile "name"
content <- readLine f    -- read first line using Latin-1
f' <- withEncoding (lookup content) f
str <- readLine f'       -- read second line using encoding given on first line

-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Libraries mailing list