Sending wide characters over the network socket

Dimitry Golubovsky dimitry@golubovsky.org
Sat, 05 Jul 2003 23:44:54 -0400


Glynn Clements wrote:


>>To be more general: how would I send arbitrary binary data (stream of 
>>octets) over a socket or a file handle? Should I always assume that only 
>>lower bytes would be sent, and this will be forever in ghc?
> 
> 
> Yes. Well, maybe not forever, but for the forseeable future.

Well, if it were there forever then one might rely upon it and just 
construct appropriate String containing only bottom octets in proper 
sequence.

> 
> 
>>Or is it a bug?
> 
> 
> No. It's just a fundamental design flaw in Haskell. Presumably someone
> thought that wide-character support was just a question of defining
> Char, and forgot about a minor issue called "I/O".

Perhaps not Haskell itself; this is just a language (i. e. a tool to 
describe some program logic). I think the problem is: I/O functions 
expose the underlying OS (Unix, Windows) to a program, and that OS has 
absolutely no knowledge of what String is in Haskell (or Java for 
example). So data chunks must be presented to those functions in the way 
  that the OS understands best. In other words, array of octets fits 
better than String. In Java runtime, this gap is filled with a bulky 
layer of various XXXOutputStream's and a bunch of encodings. I guess, 
Haskell implementation could just enhance the IO subsystem by adding 
functions taking arrays of octets as their arguments instead of 
String's. This would not break compatibility with existing programs 
using String's.

What would be really nice to have is some sort of object input/output 
over network. Then, by sending a String, I would expect it to be 
recreated at the other end. And if the other end expects, say [Int] then 
an error would be detected. I haven't looked through the whole GHC 
runtime, and maybe something like this is already there, any clue is 
welcome.


-- 
Dmitry M. Golubovsky
       South Lyon, MI