[m-dev.] stream typeclasses (again)
Julien Fischer
juliensf at cs.mu.OZ.AU
Sun Mar 19 23:59:32 AEDT 2006
On Sun, 19 Mar 2006, Ian MacLarty wrote:
> > > > > 2. Do away with the Stream argument and just have a di, uo pair of polymorphic
> > > > > states. Something like:
> > > > >
> > > > > :- typeclass stream.input(Unit, State) where [
> > > > > pred get(Unit::out, State::di, State::uo) is det
> > > > > ].
> > > > >
> > > > > File streams could be implemented by embedding the IO state, together
> > > > > with the file handle and name in the State type.
> > > > >
> > > > > We'd also then be able to define forwarding streams like my version
> > > > > of rot13 nicely:
> > > > >
> > > > > :- type encryption_stream_state(S)
> > > > > ---> encryption_stream_state(
> > > > > stream_state_to_forward_to :: S,
> > > > > internal_encryption_state :: ...
> > > > > ).
> > > > >
> > > > > :- instance stream.output(string, encryption_stream_state(S)).
> > > > >
> > > > > This instance declaration conforms to the current restrictions.
> > > > >
> > > > > With such a scheme we could also ensure that closed streams are never
> > > > > used, by clobbering the stream when it's closed.
> > > > >
> > > > > Do you think the mode system is up to the task? I don't see why it
> > > > > wouldn't be, since it handles di, uo pairs for IO just fine.
> > > >
> > > > I think that embedding the I/O state inside anything tends to lead to
> > > > highly confusing code; it's something I would prefer to avoid.
> > > >
> > >
> > > Ralph makes a good point too. Let's go with the first approach, i.e:
> > >
> > > :- typeclass input(Stream, Unit) where [
> > > pred get(Stream::in, Unit::out, io::di, io::uo) is det
> > > ].
> > >
> >
> > Ok. I'll take a look at it in the next couple of days (if you don't
> > get there before me). BTW, I've almost finished a change that fixes
> > the problems with file streams in the io module overlapping when used
> > in typeclass instances.
> Cool. Let me know what changes you want me to do. There's no point
> us both making the same changes. Once the new stream module has been
> reviewed and committed I'll update term_to_xml.
The io module changes are ready to modulo a bug with the handling
of termination pragmas that stops the libray bootstrapping and
sorting out how the debugger and io.write should print out streams
I'll try and post a revised version of the stream module sometime later
this week.
term_to_xml is your problem :-)
Julien.
--------------------------------------------------------------------------
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