[erlang-questions] Runtime checking for types
Mon Apr 18 21:30:32 CEST 2011
On Mon, Apr 18, 2011 at 7:09 PM, Steve Davis <steven.charles.davis@REDACTED
> Interesting response. Actually, I find myself in disagreement here. Let
> me explain further.
> There's two precepts at the heart of my personal Erlang journey and
> experience that are somewhat in opposition to your statements (and
> appear to me to be in direct opposition!):
> 1) Let it crash!
> 2) Checks are only required at the boundary of the system.
> For "type safety" I find pattern matching and guards quite adequate,
> even as a codebase grows. Also, the BEAM VM seems pretty good at
> optimizing such dynamic checks.
> Of the other approaches in Erlang that attempt to enhance type checking,
> the only one that appeared _to me_ to have any true elegance was UBF
> I rather suspect that the lack of further static type checking in Erlang
> wasn't because the creators didn't have time, but rather that, given the
> precepts above, it wasn't considered *useful* or necessary. ...that's my
> take on things of course, and I'd be interested in how far that is true.
> Perhaps Joe or Robert may weigh in with a comment on that.
Erlang evolved from Prolog. The first Erlang was just a meta-interpreter
written in Prolog
to add processes and message passing to Prolog.
Prolog had dynamic types therefore Erlang had dynamic types - no thinking
Nothing to do with lack of time. As the language evolved we were more
things like error recovery than static type checking.
The stuff that we really thought long and hard about was not type checking
error checking. The link mechanism, for example, is something that I think
is unique to Erlang.
Processes communicate errors "out of band" this means you can write your
regular inter-process message passing using regular RPCs and the RPC like
code does not need to
check errors caused by out-of-band behavior (exceptions). Exceptions
links and are handled elsewhere.
The exception mechanism works just like a traditional try-catch where
are thrown up the call stack to an enclosing catch, but if there is no
the exception propagates out of the processes and is sent as a single to any
The particuar combinations of links/spawn_link/process_flag(trap_exit, ...)
were arrived at after much though, discussion and experimentation. These are
sort of questions we were worrying about - not type systems. Why these
Easy - because we wanted to build real-world fault tolerant systems. Getting
right was essential. Systems we built using these techniques have been
many years now, switching millions to billions of users sessions/day.
When people say "language X has Erlang like semantics" they virtually always
"language X has processes, mailboxes and message passing" and non of the fun
(links, exit signals, linked process groups).
Erlang is pretty good at what it was designed to be good at - namely
building fault tolerant
systems. It was not designed with static type checking in mind.
> Also, I'm wondering whether your (amazing!) work with erjang and the JVM
> hasn't influenced your response, here. Especially with regard to the
> apparent "richness" and efficiency? Contrarily, I have found dynamic
> typing a blessed relief from the verbosity that occludes the value of
> languages with greater levels of static type-checking.
> With the greatest respect, if Erlang (+OTP) had taken the path you
> suggest, I suspect I would find it far less attractive as a platform.
> Best regards,
> On 4/18/2011 5:58 AM, Jesper Louis Andersen wrote:
>> On Mon, Apr 18, 2011 at 01:07, Steve Davis
>> <steven.charles.davis@REDACTED> wrote:
>>> IMHO, a focus on type-safety can lose you a truly *massive* amount of
>>> time that could be spent doing something useful.
>> There are many intricate dependencies which you can't simply resolve
>> in a few moments of thought on that one. The point of type safety is
>> to trade a short-term added specification for a long-term benefit. You
>> write down a precise expression of intent with the type, and being
>> precise takes more time. But it is extremely helpful over the course
>> of larger programs, provides (checkable!) documentation, yields more
>> effective execution trivially and so on.
>> The initial ignorance of static types in Erlang is understandable.
>> Other things were more important to get right and history was such
>> that we did not understand certain parts of the intermingling of types
>> with distribution etc.. But today, I feel there is no excuse. Should I
>> design a modern Erlang, I would start with a statically typed world in
>> which communicaiton use polymorphic variants. Essentially: An internal
>> process is statically typed, but communicate in a dynamically typed
>> setting. Thus, I have lost *nothing* compared to Erlang, but I can
>> compile processes to be an order of magnitude faster, trivially. From
>> there, I can probably define a channel-primitive between processes
>> with static type constraint such that processes can intercommunicate
>> in a type-safe way. Perhaps even with a shared-persistent-heap
>> Remember, dynamic typing is a straitjacket, in which you cannot fully
>> express yourself, whereas static typing give you a rich language for
>> doing so.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions