On Tue, 2006-12-05 at 20:12 +1100, skaller wrote:
> On Mon, 2006-12-04 at 23:10 -0800, Erick Tryzelaar wrote:
> > typeclass Readable_iterator[it,t] {
> > virtual fun deref: it -> t;
> > }
> >
> > typeclass Writable_iterator[it,t] {
virtual proc store: it * t;
> > }
BTW: it isn't clear even this is quite the right classification.
Some iterators return rvalues (perhaps input iterator).
Some permit storing (output iterator).
However iterators that return an lvalue are different:
they support reading and or writing and or arbitrary
modification (such as incrementing the value, calling
a method, etc etc) depending on the C++ type. That type
includes constness. As mentioned for some types like
map's value type which is a
pair<key const, value>
if the iterator returns a non-const lvalue you can
modify the value part of the key. Modify is much stronger
condition than reading or writing.
Above your 'store' procedure doesn't even require the
iterator to support reading: C++ iterators returning
proxies which support only writing exist, although
this is a very broken technique compared with your
store procedure (since there's no requirement to
be able to 'dereference' the iterator).
Of course more generally you could have any kind
of weird method eg:
proc store_value: it * value;
where the iterator refers to a pair<key const, value>.
In the end all these cases show a serious problem with
the C++ type system.
The STL stuff I've implemented is a simplification.
No support for 'const' for example, since Felix itself
doesn't have any such concept (at the moment anyhow).
As far as I'm concerned every 'reference' to store is
writable. This does leave C++ things we can't model
in Felix. It isn't clear we lose much.
Don't forget, STL containers can't hold Felix values anyhow,
so we'll probably have to replace them -- we already have
a list, a more useful array will turn up some time,
and we have an AVL tree.
There's a clash here: C++ type system is crap, Felix is
supposed to have a better one, so there is a tension
trying to model the whole C++ type system in Felix,
since that would simply result in a reflection of
what we're trying to improve on.
--
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