This was raised on Facebook but my response is going here.
Should go in a blog of course .. :)

I content that only a strongly typed language can be highly dynamic.
An interesting point was made by someone on Y-combinator that
a scripting language should be defined by possession of an eval() function.

Felix currently doesn't have eval. languages like Python do.
In my Interscript tool a Python program read files containing Python
which it executed with (something like eval).

It's easy enough to write an evaluator IN a strongly typed language.
But "eval" is not any old evaluator. It isn't just en evaluator for the
source language either -- Felix could do that easily by just calling
"flx" using the system() or popen() commands. What makes eval()
special is that the evaluated code is evaluated in the "current context"
which means it binds to symbols in that context.

Of course this causes all hell to break lose, and the features is frowned
on in most languages, and also very rarely used.

In this sense, Felix isn't a scripting language: there's no eval(),
the closest we come is dynamic linkage and dynamic binding to 
symbols with dlopen() in shared libraries.

Still, Felix is capable of a high level of dynamism. As is Ocaml
and C++. More than Python or Perl or Lua!

Dynamism doesn't mean dynamic typing. In fact most "dynamically
typed" language severely LACK dynamism. Consider core
types in Python:

        a + b

Well, its dynamic you say because a could be an int or a long
or a string.

Yes .. and .. and .. and anything else? Yes, a class. That's it.
To do more .. you have to write a C extension. And because of the
stupid OO basis of the system, you're limited what you can add to:
at best you can only add to the few types you happen to know about.

On the other hand in Felix all you need is this:

        class Addable[A,B] { virtual fun + : A * B -> A; }

for example and you can add any pair of types (yielding the first
one in this case). Of course yes, you have to implement the
combinations you want. But you aren't screwed up by having
to break encapsulation .. especially in a C extension  .. to do that.

You also aren't limited to +, - * and / and a few other functions,
as you are in Python. Of course with classes you're more flexible,
you can add more methods at whim .. but you cannot implement
most of the combinations because you cannot dispatch to them:
the dispatch method itself is the limitation.

In Felix on the other hand dispatch is multiple dispatch.
It's based on any number of types.

Statically typed languages also typically provide powerful
features that are sometimes lacking in dynamic languages.
Such as closures. Iterators. Cooperative multi-tasking
with channels.

It is in fact the static typing which *enables* these dynamics,
and the enablement comes as usual by imposing constraints.

The more restrictions you have the freer your are :)

There's a convincing example in Felix: the Java like Object system.
This is syntactic sugar. An object is just a record of functions closed
over the environment of the constructor function. Entirely statically typed.

Yet, you can swap a method f from "object A" to "object B" 
so when you call f on A it modifies the state of B -- that's pretty
dynamic! In fact you can replace any of these closures with any
closure at all, provided it has the right type.

And what I ask happens when you call a Python method with
the wrong type of arguments?

It fails. Same as in Felix. Only the time of failure differs.
Python is only more dynamic because an incorrectly
typed call can exist, and you get no error if control never
flows through that call.

In balance then, dynamic typing actually *destroys* dynamism
rather than enabling it. High power static typing is what allows
you to write dynamic programs.

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to