Tim
Tim

Reputation: 99428

What kinds of declarations does an environment in SML consist of?

In SML, an environment consists of bindings of variables and their denoted values.

Does an environment consist of bindings of which of the following declarations?

Upvotes: 0

Views: 156

Answers (2)

Andreas Rossberg
Andreas Rossberg

Reputation: 36098

The environment for the core language only has three components: values, types, and structures. For values, besides recording the identifier's type, it also marks whether it is a constructor.

The value environment is extended by val, fun (just a shorthand for val), datatype, exception, and (deprecated) abstype declarations.

The type environment is extended by type, datatype, and abstype declarations.

The structure environment is only extended by module-level declarations. The module level additionally adds a functor and a signature environment.

Local declarations just control the extend of these environments, they don't require their own environment.

Fixity is handled during parsing, so doesn't have an environment during type checking. Though technically, it requires one during parsing.

Interestingly, the SML semantics is defined such that it doesn't need an environment for type variables 'a, 'b, etc.

Upvotes: 2

ruakh
ruakh

Reputation: 183341

If you're using the terminology of The Definition of Standard ML (Revised), then an environment consists of a value environment, a type environment, and a structure environment. These environments can be updated by any type of declaration, except for infix/infixr/nonfix declarations (which are just handled as syntactic transformations) and signature and functor declarations (which contribute to signature and functor environments, respectively, which despite their names are not part of the "environment", but rather, are directly part of a higher-level object, called the "basis", which includes the environment).

Upvotes: 1

Related Questions