[erlang-questions] dialyzer and behaviours
Richard A. O'Keefe
ok@REDACTED
Mon Jul 21 02:25:49 CEST 2014
On 20/07/2014, at 10:10 AM, Siraaj Khandkar wrote:
> On 07/17/2014 08:02 PM, Richard A. O'Keefe wrote:
>>
>> On 17/07/2014, at 5:12 PM, Siraaj Khandkar wrote:
>>> In a statically typed language with a module
>>> system it'd be something like:
>>>
>>> signature MY_DB =
>>> sig
>>> val table : unit -> iolist
>>> end
>>>
>>> functor Foo (Db_impl : MY_DB) =
>>> struct
>>> ...
>>> end
>>
>> The tricky thing here is that ML has been implemented
>> in two ways:
>> ML
>
> Richard, the suspense is killing me! :-)
I did _write_ the second half of the message....
ML has been implemented in (at least) two ways:
MLton: static whole-program compilation.
SML/NJ, Poplog, &c: dynamic incremental loading.
The incremental loading approach is the one that's
relevant here, BUT 'loading' is assimilated to
'lexically nested inside'. So if you do
use "A.ml";
this introduces a number of bindings into the static
environment, then
use "B.ml";
uses those bindings and introduces more, then
use "A.ml";
introduces *new* bindings for A which *hide* the
old ones from any subsequent loading, but DO NOT
REPLACE the old bindings. B is still linked to
the bindings from the old version of A.
Here's an actual example.
m% sml
Standard ML of New Jersey v110.73 [built: Sun May 15 21:34:53 2011]
- (* A.ml contains 'val x = 1' *)
- use "A.ml";
[opening A.ml]
val x = 1 : int
val it = () : unit
- (* B.ml contains 'val y = x' *)
- use "B.ml";
[opening B.ml]
val y = 1 : int
val it = () : unit
- (* in another window, A is now changed to 'val x = true' *)
- use "A.ml";
[opening A.ml]
val x = true : bool
val it = () : unit
- (* we see that y still refers to the old x *)
- y;
val it = 1 : int
- <EOF>
So ML is not an example of a hot-loading system with strong
types. It's close enough to hot loading for interactive
development, provided you remember that when you "replace"
a module you have to "replace" every module that depended on
it, which is why CM exists.
More information about the erlang-questions
mailing list