Length of an SLIst ?

bearophile bearophileHUGS at lycos.com
Mon Apr 2 14:53:15 PDT 2012


Steven Schveighoffer:

> It all depends on how you model the data.  If the data is 
> contained/owned by a single instance, then you can store the 
> length inside that instance.  If it's not owned (i.e. sublists 
> are also valid SLists) then you cannot do that.

Let me add something to your answer. With Dependent Types
(http://en.wikipedia.org/wiki/Dependent_types ) you are sometimes
able to use the list length, encoded in the types, despite at
run-time the lengths aren't stored in the run-time data structure
:-)

This is not always possible, and it generally requires a type
system more powerful than the D type system if you also want it
to be sufficiently handy to use.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list