I am playing around trying to find typeclass models suitable
for modelling the various stream I/O operations the demux/faio
subsystem of Felix provides. This system provides portable
sockets, timers, and asynchronous file I/O. A fairly simple
basic pair is:

typeclass IStream[f,t] {
  virtual gen read: f -> t;
}

typeclass OStream[f,t] {
  virtual proc write: f * t;
}

however sockets and files are not really streams:
streams are infinite. This is one fix:

typeclass IFile[f,t] {
  inherit IStream [f,opt[t]];
}

but it doesn't really account for, say, reading
a socket and finding no data, unless t = string,
in which case we might return an empty string.
Mu output file:

typeclass OFile[f,t] {
  inherit OStream;
  virtual proc close: f; // invalidates write operation
}

allows the writer to close the file. Note the reader cannot.
For lower level access:

typeclass IBuffer [f] {
  virtual gen read: f -> address * int -> bool;
}

typeclass OBuffer [f] {
  virtual gen write : f -> address * int -> bool;
}

where bool is an error indicator. To actually communicate
error information would require an additional parameter.

None of this fits well with iterator typeclasses. There is a
technical problem with typeclasses here:

typeclass Iterator[it,t] {
  virtual fun deref: it -> lvalue[t];
}

Iterators must return a lvalue in this model.
However STL input iterators only return a value,
for iterators this is 'firmed up' to a value:
this is a convariant functor at work but Felix doesn't
support functor subtyping (it supports parametric
subtyping though, i.e it knows t * t is a subtype
of u *  t).

ANYHOW the question is: how can we make all this I/O stuff simpler
for end users?


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to