Re: Benefits of Dynamic Typing



Abdulaziz Ghuloum wrote:
> Jon Harrop wrote:
>> ...
>> For example, I posted a simple 1-line OCaml program and asked him for the
>> C equivalent. Neglecting reliability, the hand-written C equivalent was
>> ~30 times as long. That difference in verbosity gets bigger with more
>> complicated programs (the ML is asymptotically more concise).
>> ...
>
> How did you arrive to the conclusion that ML is asymptotically more
> concise than C?

This does not apply to metaprogramming (where you write the relevant part of
an ML compiler in C and use it to generate C code, or to interpret an
equivalent program), only to "straightforward" translations.

The simplest example is the exponential complexity of ML's type inference.
You can write a tiny ML definition that has a huge type (I gave an example
in the other thread). To write a C equivalent of this, you must roll your
own intermediate values, all of which are closures in this case (no native
higher-order functions or curried functions). This requires you to
determine which values are captured in the environments of each closure by
hand (no native closures) as well as their lifetimes (no GC). So the amount
of C code grows exponentially when the amount of ML code is growing only
linearly.

In reality, programs don't use such expressions, which is why ML's
exponential complexity for type inference is not a problem in practice.
However, it is well known that use up to 6th-order functions are not
uncommon in real programs. It is hairy enough to write such things without
static type checking, but without GC and closures it soon becomes
intractable.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.



Relevant Pages


Loading