TypeAnal Module

This module defines type analysis routines for pretypes and preterms, used in parsing and printing type/term quotations. The primary routines are detyping, type unification, type inference and type consistency check. This module is used in the implementation of the pretty printer, and is a trusted component of the system.

Types

Type Description

varenv

Functions and values

Function or value Description

annot_error

Full Usage: annot_error

Returns: string * string
Returns: string * string

arity_error (x, n1, n2)

Full Usage: arity_error (x, n1, n2)

Parameters:
    x : string
    n1 : 'a
    n2 : 'b

Returns: string * string
x : string
n1 : 'a
n2 : 'b
Returns: string * string

basic_unify_pretypes (pty1, pty2)

Full Usage: basic_unify_pretypes (pty1, pty2)

Parameters:
Returns: (pretype * pretype) list

This takes two pretypes and returns an old-to-new instn list for generated tyvars, calculated by comparing corresponding subcomponents of the pretypes. This instn list is not necessarily closed (i.e. it may need to be applied repeatedly until it makes no change) and may contain inconsistencies when when the two pretypes cannot be unified (instead of failing). These are dealt with by instantiation closure (see below).

pty1 : pretype
pty2 : pretype
Returns: (pretype * pretype) list

check_preterm_annotations tm ptm

Full Usage: check_preterm_annotations tm ptm

Parameters:
Returns: preterm
tm : term
ptm : preterm
Returns: preterm

check_pretype pty

Full Usage: check_pretype pty

Parameters:
Returns: pretype
pty : pretype
Returns: pretype

close_all_names (theta, venv)

Full Usage: close_all_names (theta, venv)

Parameters:
Returns: (pretype * pretype) list
theta : (pretype * pretype) list
venv : (string * pretype list) list
Returns: (pretype * pretype) list

close_name (x, pty) (theta, venv)

Full Usage: close_name (x, pty) (theta, venv)

Parameters:
Returns: (pretype * pretype) list * varenv
x : string
pty : pretype
theta : (pretype * pretype) list
venv : (string * pretype list) list
Returns: (pretype * pretype) list * varenv

close_name0 venv x theta

Full Usage: close_name0 venv x theta

Parameters:
Returns: (pretype * pretype) list
venv : (string * pretype list) list
x : string
theta : (pretype * pretype) list
Returns: (pretype * pretype) list

detype_preterm ptm

Full Usage: detype_preterm ptm

Parameters:
Returns: preterm
ptm : preterm
Returns: preterm

detype_preterm0 ptm

Full Usage: detype_preterm0 ptm

Parameters:
Returns: preterm
ptm : preterm
Returns: preterm

fun_error1

Full Usage: fun_error1

Returns: string * string
Returns: string * string

fun_error2

Full Usage: fun_error2

Returns: string * string
Returns: string * string

generate_const_preterm x

Full Usage: generate_const_preterm x

Parameters:
    x : string

Returns: preterm
x : string
Returns: preterm

generate_var_preterm x

Full Usage: generate_var_preterm x

Parameters:
    x : string

Returns: preterm
x : string
Returns: preterm

infer_pretypes ptm

Full Usage: infer_pretypes ptm

Parameters:
Returns: (pretype * pretype) list
ptm : preterm
Returns: (pretype * pretype) list

infer_pretypes0 ptm

Full Usage: infer_pretypes0 ptm

Parameters:
Returns: pretype * (pretype * pretype) list * (string * pretype list) list
ptm : preterm
Returns: pretype * (pretype * pretype) list * (string * pretype list) list

new_pretype_gvar ()

Full Usage: new_pretype_gvar ()

Parameters:
    () : unit

Returns: pretype
() : unit
Returns: pretype

overload_error x

Full Usage: overload_error x

Parameters:
    x : string

Returns: string * string
x : string
Returns: string * string

pretype_gvar_counter

Full Usage: pretype_gvar_counter

Returns: int ref
Returns: int ref

pretype_ok pty

Full Usage: pretype_ok pty

Parameters:
Returns: bool

Checks that the supplied pretype is well-formed, by checking that all compound types have the correct arity for the type constant involved. This gets used on stand-alone type quotations and on types embedded as type annotations in term quotations.

pty : pretype
Returns: bool

reset_pretype_gvar_counter ()

Full Usage: reset_pretype_gvar_counter ()

Parameters:
    () : unit

() : unit

resolve_preterm ptm

Full Usage: resolve_preterm ptm

Parameters:
Returns: preterm

Replaces the generated tyvars in the supplied preterm with their most general valid pretypes, deduced from type inference. Note that the preterm input is assumed to have been detyped.

ptm : preterm
Returns: preterm

theta_closure theta0 theta

Full Usage: theta_closure theta0 theta

Parameters:
Returns: (pretype * pretype) list

Takes an existing closed pretype instn list 'theta0' and a second (not necessarily closed or consistent) pretype instn list 'theta', and incorporates 'theta' into 'theta0', resulting in either a new closed instn list or failure (if inconsistencies exist in 'theta' wrt 'theta0').

theta0 : (pretype * pretype) list
theta : (pretype * pretype) list
Returns: (pretype * pretype) list

theta_inst theta0 theta

Full Usage: theta_inst theta0 theta

Parameters:
Returns: ('a * pretype) list
theta0 : (pretype * pretype) list
theta : ('a * pretype) list
Returns: ('a * pretype) list

type_err msg

Full Usage: type_err msg

Parameters:
    msg : string

Returns: 'a
msg : string
Returns: 'a

type_fail_info msg

Full Usage: type_fail_info msg

Parameters:
    msg : 'a

Returns: string * 'a
msg : 'a
Returns: string * 'a

types_error

Full Usage: types_error

Returns: string * string
Returns: string * string

unify_pretype_list theta0 ptys

Full Usage: unify_pretype_list theta0 ptys

Parameters:
Returns: (pretype * pretype) list

Unifies all pretypes in the supplied list with each other, incorporating the result into existing closed instn list 'theta0'.

theta0 : (pretype * pretype) list
ptys : pretype list
Returns: (pretype * pretype) list

unify_pretype_pairs theta0 ptyptys

Full Usage: unify_pretype_pairs theta0 ptyptys

Parameters:
Returns: (pretype * pretype) list

Unifies the left pretype with the right pretype of each pair in the supplied list, incorporating all the results into existing closed instn list 'theta0'.

theta0 : (pretype * pretype) list
ptyptys : (pretype * pretype) list
Returns: (pretype * pretype) list

unify_pretypes (pty1, pty2)

Full Usage: unify_pretypes (pty1, pty2)

Parameters:
Returns: (pretype * pretype) list
pty1 : pretype
pty2 : pretype
Returns: (pretype * pretype) list

unify_pretypes0 theta0 (pty1, pty2)

Full Usage: unify_pretypes0 theta0 (pty1, pty2)

Parameters:
Returns: (pretype * pretype) list

Unifies any generated tyvars in input pretypes 'pty1' and 'pty2', to result in either a closed pretype instn list for making them equal, or failure (when the pretypes cannot be unified). In 'unify_pretypes0', the unification is carried out wrt input pretype instn list 'theta0', and the result incorporates 'theta0' (but with its range instantiated according to the unification). Note that 'theta0' is assumed to be closed.

theta0 : (pretype * pretype) list
pty1 : pretype
pty2 : pretype
Returns: (pretype * pretype) list

varenv_inst theta venv

Full Usage: varenv_inst theta venv

Parameters:
Returns: varenv
theta : (pretype * pretype) list
venv : varenv
Returns: varenv

varenv_subtract venv (x, pty)

Full Usage: varenv_subtract venv (x, pty)

Parameters:
Returns: varenv
venv : varenv
x : string
pty : pretype
Returns: varenv

varenv_union venv1 venv2

Full Usage: varenv_union venv1 venv2

Parameters:
Returns: varenv
venv1 : varenv
venv2 : varenv
Returns: varenv