Optional Static Typing - Haskell?

Donn Cave donn at drizzle.com
Fri Dec 24 20:14:35 EST 2004


Quoth aleaxit at yahoo.com (Alex Martelli):
| Donn Cave <donn at drizzle.com> wrote:
...
| > He didn't dwell much on it, but there was some mention of type
| > inference, kind of as though that could be taken for granted.
| > I guess this would necessarily be much more limited in scope
| > than what Haskell et al. do.
|
| Assuming that by "he" you mean GvR, I think I saw that too, yes.  And
| yes, a language and particularly a typesystem never designed to
| facilitate inferencing are hard-to-impossible to retrofit with it in as
| thorough a way as one that's designed around the idea.  (Conversely,
| making a really modular system work with static typing and inferencing
| is probably impossible; in practice, the type inferencer must examine
| all code, or a rather copious summary of it... it can't really work
| module by module in a nice, fully encapsulated way...).

Well, I would assume that a modules in a static system would present
a typed external interface, and inference would apply only within the
module being compiled.

for example, Objective CAML revised syntax -

  $ cat mod.ml
  module T =
    struct
       type op = [On | Off];
       value print t a = match t with
          [ On -> print_string a | Off -> () ];
       value decide t a b = match t with
          [ On -> a | Off -> b ];
    end;

  $ ocamlc -i -pp camlp4r mod.ml
  module T :
    sig
      type op = [ On | Off ];
      value print : op -> string -> unit;
      value decide : op -> 'a -> 'a -> 'a;
    end;

This is fairly obvious, so I'm probably missing the point,
but the compiler here infers types and produces an interface
definition.  The interface definition must be available to
any other modules that rely on this one, so they are relieved
of any need to examine code within this module.

There might be tricky spots, but I imagine the Objective CAML
folks would object to an assertion like "making a really modular
system work with static typing and inferencing is probably
impossible"!

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list