[mercury-users] network programming

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 10 21:38:17 AEDT 1998


On 10-Mar-1998, Paul Massey <pma at miscrit.be> wrote:
> 
> Found it, but I have not idea why I don't remember it. Maybe
> something got in the way (normally I would have responded to
> the point you raised). My apologies ....
> 
> Fergus> Hmm.  This has the disadvantage of losing some type
> Fergus> checking.  For example, the compiler won't complain
> Fergus> if you pass an input_stream where an output_stream
> Fergus> is expected.
> 
> I knew this would happen, but wanted something reasonably
> quickly which didn't entail rewriting the io.m module.

I understand this.  The long-term solution will be to use
some mechanism that has better support for subtyping, e.g. type classes.

However, I'd still rather not lose type checking in the medium-term.
I think I'd prefer having several versions of `io__fd_to_stream'
and `io__stream_to_fd' rather than losing type safety.

(Doing otherwise sort of violates the principle that you
shouldn't have to pay for something that you're not using:
people who are not using these predicates should not lose type safety.)

> Fergus> write_string(output(BidirectionalStream), "What is your name?\n"),
> Fergus> read_line(input(BidirectionalStream), Result)
> Fergus> instead of 
> Fergus> write_string(BidirectionalStream, "What is your name?\n"),
> Fergus> read_line(BidirectionalStream, Result)
> 
> For every I/O statement that's a lot of extra typing,

Those extra 7 or 8 characters?  I don't find this convincing.

If number of characters typed is a major issue, you can have

	io__set_current_io(BidirectionalStream) -->
		io__set_current_output(output(BidirectionalStream))
		io__set_current_input(input(BidirectionalStream)).

and then you can just use

	io__set_current_io(BidirectionalStream),
	write_string("What is your name?\n"),
	read_line(Result)

> This could be changed easy enough I would guess 
...
> That could be changed ..
...

OK, so you have two choices:
	(a) change them, and send us the revised diff
	(b) wait, in the hope that eventually we will do this ourselves
	    (or someone else will do it).

Personally I'd prefer it if you choose (a), but it is of course
up to you!

Cheers,
	Fergus.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list