Re: Homogeneous sequence

new topic     » goto parent     » topic index » view thread      » older message » newer message

Robert Craig wrote:

> CChris wrote:
> > You are painfully aware that type checking has a O(N) complexity, where N is
> > not the legth, but the number of all atoms in all your subsequences. Reguar
> > type checking is probably very inefficient here.
> 
> This reminds me of a proposed extension to the type system
> that various people, including myself, have thought about before.
> It would be intuitively clear, and somewhat useful, to allow
> type declarations such as:
> }}}
<eucode>
>   sequence of integer x
>   sequence of object x
>   sequence of sequence x
>   sequence of sequence of atom x
>   sequence of my_user_defined_type x
>   etc.
> </eucode>
{{{

> 
> In many cases this would reduce the type-checking cost from
> O(n) to O(1), since the type-check could be limited to a
> single value, e.g.
> 
>   x[5] = expression
> 
> would only have to test x[5], not all of x, as you would need
> today if you made your own user-defined type that loops over
> all of x to enforce that it only contain elements of say
> integer, or some other type.
> 
> Stricter types would help to catch bugs earlier in the code, 
> and document variables more precisely.

I really like this suggestion. It would be a "natural" extension
of Euphoria's current type system.

> Type information, such as this, could also in many cases 
> help the Translator to produce slightly faster C code.
> 
> I spent a lot of time thinking about this a few years ago.
> I didn't proceed with it because:
>   
>   * I was worried that since the existing user-defined type
>     system is not used all that much, perhaps this enhancement
>     to the type system would not be used much either. People 
>     might be content to just say:
>          sequence x
>     rather than the much wordier:
>          sequence of integer x
>     On the other hand, this enhancement might encourage much more
>     use of user-defined types.

This is hard to predict IMHO.

>   * Newbies might be confused, and put off by all this, 
>     thinking it was somehow necessary to provide full and proper
>     types for everything.

This would be my main concern. However, I think it can be avoided by
good documentation. The current Eu documentation IMHO is good or very
good. If explanations concerning the extended type system will be
written in the same clear and precise way, neither too short nor too
long, then people should easily understand it.

>   * It seemed at the time to be a fair bit of work, and extra 
>     baggage added to the language, for just a small gain.

I don't have enough knowledge about Eu's internals, so I can't judge
how "bad" that is.

>   * In many cases, the Translator deduces this information by
>     examining all uses of a variable across the whole program.

Cool!
Maybe it would be interesting to know, how many people translate their
programs, and how many people prefer to bind their programs.
For instance IIRC reverse-engeneering of bound programs is harder than
reverse-engeneering of translated/compiled programs, right?. If so, then
this might be a reason for people to prefer to bind their programs rather
than translate/compile them.

> But perhaps we should reconsider this idea.

My personal vote is "yes" -- being not the one who'll have to do
the work. smile

Regards,
   Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu