HELP EXTERNAL                                  Robert Duncan, April 1990

The external declaration form.


      CONTENTS - (Use <ENTER> g to access required sections)

  1   Introduction

  2   Syntax

  3   The Pop-11 Interface


-----------------------------------------------------------------------
1  Introduction
-----------------------------------------------------------------------

The external declaration is an additional top-level declaration form
unique to Poplog ML which allows ML identifiers to be declared in non-ML
languages. Currently the only language directly supported by this
interface is Pop-11. It is hoped that other languages will be supported
in the future, but in the meantime it is possible to use Pop-11 as a
bridge to all the other Poplog languages, as well as to foreign
languages such as C, Fortran, etc.

For any mixed-language programming involving ML, a sound knowledge of
the principles underlying ML data representation is essential. As a
first step, you should read and understand HELP * MLINPOP.


-----------------------------------------------------------------------
2  Syntax
-----------------------------------------------------------------------

The external declaration form extends the syntax of ML top-level
declarations as described in HELP * SYNTAX (External Declarations). The
syntax has to be a compromise between the syntax of ML and the syntax of
the external language.

The symbol external is an additional reserved word of PML.


-----------------------------------------------------------------------
3  The Pop-11 Interface
-----------------------------------------------------------------------

In the Pop-11 interface, external bindings are written in Pop-11: the
method of implementation is simply an escape to the Pop-11 compiler. For
each kind of binding -- val, type, etc. -- the syntax is exactly that of
the corresponding Pop-11 syntax word -- ml_val, ml_type, etc. --
described in HELP * MLINPOP. As far as possible, the syntax is designed
to mirror the equivalent pure ML forms.

Examples:

    external val x : int = 3;
    val x = 3 : int

    external val l : int list = [% repeat 10 times 3 endrepeat %];
    val l = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3] : int list

    external val time : unit -> int = erase <> systime;
    val time = fn : unit -> int

    time();
    val it = 11348 : int

As a fuller example, we can define an abstract data type symbol based
on the Pop-11 type word:

    signature Symbol = sig
        type symbol
        val symbol : string -> symbol
        val string : symbol -> string
    end;

    external structure Symbol : Symbol = struct
        ml_type symbol;
        ml_val symbol : string -> symbol = consword;
        ml_val string : symbol -> string = word_string;
    end;

    Symbol.symbol "example";
    val it = - : Symbol.symbol

    Symbol.string it;
    val it = "example" : string


--- C.all/pml/help/external
--- Copyright University of Sussex 1994. All rights reserved.
