[m-dev.] for discussion: stream library v2
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Sep 28 15:41:31 AEDT 2000
On 28-Sep-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
>
> Lowlevel provides throwing exceptions, grabbing error messages, results
> packaged into ok/error/eof, and turning C style handle based IO into
> Mercury di/uo. That's all it does. But it's something you'll have to
> do and get right every time you implement a stream.
Sure. But IMHO the natural place to turn C style handle based IO
into Mercury di/uo is at the Mercury <-> C interface, whereas this
`lowlevel' module keeps C style handle based IO around in the Mercury
code which implements the layer that provides throwing exceptions,
grabbing error messages, and packaging results in ok/error/eof.
> There is absolutely *nothing less pure* about doing things this way.
> The C code is still underneath any interface you might write that
> targets the highlevel typeclass. But you have to write all the
> scaffolding yourself. The "new stream" stuff in the current IO library
> does almost exactly this stuff but a lot more is in C!
It depends what you're comparing against.
If you're comparing against the current "new stream" stuff
or against just having the highlevel interface, you're right.
But if you're comparing against having a pure version of
the low-level interface, then it is less pure.
> Fergus suggests that we could do the di/uo pairing in C, and lowlevel
> could provide an interface that just does ok/error/eof and exception
> throwing (e.g. much like what we have in the current IO library).
>
> IMHO is a reasonable suggestion -- an interface at that level might be
> useful too. Given that we don't have `ui' mode support at the moment,
> this might be the right thing to do for now. I like the idea of using
> typeclasses to automatically implement patterns for turning impure code
> into pure code, but I think in this case the pattern is sufficiently
> simple that it won't necessarily hurt us to do it by hand.
If you do that conversion at the C <-> Mercury interface, then it
basically takes no work -- you just use "pragma import" or "pragma
c_code" as usual, the only difference is whether you declare the
procedure as "impure func foo(...) = ..." or as
"pred foo(..., S::di, S::uo)".
> So how about if lowlevel is a pure interface that does everything
> lowlevel currently does *except* it already expects di/uo stream pairs.
Sounds good to me.
--
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.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list