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

  • Re: Java or C++?
    ... > Jon Harrop wrote: ... >> defined in the presence of closures because they can capture and carry ... it just automates much of the work for you. ... occurrence in functional languages). ...
    (comp.programming)
  • Re: various forms of generic programming?
    ... Jon Harrop wrote: ... modules and comparatively poor type inference. ... Firstly Haskell doesn't need ...
    (comp.lang.functional)
  • Re: Newbie Question: Is it allowed for the function to change the value of parameters?
    ... Jon Harrop wrote: ... Perhaps you meant the difference between procedures and closures? ... The distinction is a bit blurry. ... follows the idea of mathematical functions (say, some lambda calculus) ...
    (comp.lang.functional)
  • Re: Function minimization and random numbers
    ... Jon Harrop wrote: ... Closures represent all functions but .NET delegates do not because .NET ... then you could say "C# supports first-class closures in the same ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: various forms of generic programming?
    ... Jon Harrop wrote: ... and comparatively poor type inference. ... but you've always failed to use Haskell properly. ... Haskell's type inference isn't poor, ...
    (comp.lang.functional)