[Haskell-cafe] Writing binary files?

Jan-Willem Maessen - Sun Labs East Janwillem.Maessen at Sun.COM
Mon Sep 13 10:43:00 EDT 2004

Glynn Clements wrote:
> Actually, the more I think about it, the more I think that "simple,
> stupid programs" probably shouldn't be using Unicode at all.
> I.e. Char, String, string literals, and the I/O functions in Prelude,
> IO etc should all be using bytes, with a distinct wide-character API
> available for people who want to make the (substantial) effort
> involved in writing (genuinely) internationalised programs.

I have become very sympathetic to this viewpoint.  In particular, it 
is nigh-impossible to just move bits into and out of a Haskell 
program.  There certainly isn't a simple, portable way to do so.  In 
the absence of such a mechanism, there are *no* *portable* *workarounds*.

The absence of real internationalization is galling, but not nearly as 
galling as the absence of simple, stupid, reproducible I/O facilities. 
  Forget even ISO-8859-1.  Just give me bytes.

> Personally, I would take the C approach: redefine Char to mean a byte
> (i.e. CChar), treat string literals as bytes, keep the existing type
> signatures on all of the existing Haskell98 functions, and provide a
> completely new wide-character API for those who wish to use it.

Much as we may hate to admit it, this would probably just work in 99% 
of all cases, and would make it a simple exercise to build working 

> Given the frequency with which this issue crops up, and the associated
> lack of action to date, I'd rather not have to wait until someone
> finally gets around to designing the new, improved,
> genuinely-I18N-ised API before we can read/write arbitrary files
> without too much effort.

This is simple stuff, and far more basic than the details of test 
representation.  Why must it be so hard?  And why must we drag 
students through the muck of allocating and managing explicit byte 
buffers and (God forbid) understanding the FFI just to get a few bytes 
on and off disk without the system monkeying with them en route?

Simplify.  Please.

-Jan-Willem Maessen

More information about the Haskell-Cafe mailing list