Documentation

Strata.DL.Imperative.PureExpr

structure Imperative.PureExpr :
Type (u + 1)

Expected interface for pure expressions that can be used to specialize the Imperative dialect.

  • Ident : Type

    Kinds of identifiers allowed in expressions. We expect identifiers to have decidable equality; see EqIdent.

  • EqIdent : DecidableEq self.Ident

    Decidable equality on identifiers.

  • Expr : Type

    Expressions

  • Ty : Type

    Types

  • ExprMetadata : Type

    Expression metadata type (for use in function declarations, etc.)

  • TyEnv : Type

    Typing environment, expected to contain a map of variables to their types, type substitution, etc.

  • TyContext : Type

    Typing context, expected to contain information that does not change during type checking/inference (e.g., known types and known functions.)

  • Factory : Type u

    Factory for function/operator resolution. A factory may also carry a semantic model (as Core's runtime factory does), which is why it lives in an arbitrary universe.

  • Val : Type u

    Runtime values held by variable stores and produced by eval. A value may record the model it was produced in; HasVal.value says which values belong to a given factory.

  • eval : self.Factory → (self.Ident → Option self.Val) → self.Expr → Option self.Val

    The expression evaluator. Takes a factory, a variable store, and an expression, and returns an optional value.

Instances For
    @[reducible, inline]
    Equations
    Instances For
      @[reducible, inline]
      Equations
      Instances For
        @[instance_reducible]

        [DecidableEq P.Ident] resolves to the bundled PureExpr.EqIdent field, keeping the term on a single instance across a proof.

        Equations

        Type Classes for Expressions #

        Instances

          Lawfulness of HasIdent: the canonical identifier-injection is injective.

          Instances
            • mkFvar : P.Ident → P.Expr
            • mkTypedFvar : P.Ident → P.Ty → P.Expr

              A free variable carrying its type. A pass that introduces a variable after type checking has run must annotate it itself, since nothing downstream will.

            • getFvar : P.Expr → Option P.Ident
            Instances

              Returns ALL operator/function names referenced in an expression (e.g., .op constructs in Lambda).

              Instances

                Lawfulness of HasFvar: variable constructors round-trip through getFvar and a typed variable contains no operator references.

                Instances

                  Multi-variable version of HasFvar.getFvar: returns ALL free variables in a (possibly compound) expression. HasFvar.getFvar only returns Some when the expression is a single fvar atom; HasFvars.getFvars recurses into compounds.

                  • getFvars : P.Expr → List P.Ident
                  • getTypedFvars : P.Expr → List (P.Ident × P.Ty)

                    The free-variable occurrences of an expression that carry a type annotation, with their annotations. There is no default: a language whose expressions carry no annotations says so with fun _ => [].

                  Instances

                    Lawfulness of HasFvars against HasFvar: the free-variable list of an mkFvar x expression, as computed by the HasFvars.getFvars extractor, is a subset of [x].

                    Instances

                      Predicates on runtime values (P.Val): which values belong to a factory (and so may be held by its stores), and which values inhabit a type.

                      • value : P.Factory → P.Val → Prop

                        v is a runtime value of factory f.

                      • valueOfTy : P.Factory → P.Val → P.Ty → Prop

                        v is a value of the monomorphic type ty.

                      Instances

                        Laws for the abstract typed-value predicate.

                        Instances

                          Boolean expressions and values. Extends HasVal P. The expression constants tt/ff are syntax; ttVal f/ffVal f are the runtime values of factory f they evaluate to (see WellFormedSemanticEvalVal).

                          Instances

                            Boolean values are values, induced by their typed-value proofs.

                            Equations
                            • ⋯ = ⋯
                            Instances For
                              def Imperative.HasFvar.mkVar {P : PureExpr} [HasFvar P] (x : P.Ident) (ty : Option P.Ty) :

                              A variable reference, annotated with ty when given.

                              Equations
                              Instances For

                                Laws for the Boolean expression constants: they read no variables.

                                Instances

                                  Boolean operations: not, and, imp.

                                  Instances

                                    Typing of expressions #

                                    The command semantics only steps when expressions evaluate, and an evaluator may fail on ill-typed expressions (Core's denotational evaluator does). These definitions state the typing assumption under which evaluation cannot fail; their consequences for commands are in Strata.DL.Imperative.CmdSemanticsProps.

                                    @[reducible, inline]

                                    The types assigned to variables, as computed by a type checker.

                                    Equations
                                    Instances For

                                      The typing judgment for expressions.

                                      • HasType : P.Factory → VarTyping P → P.Expr → P.Ty → Prop

                                        e has type ty under factory f when each free variable x has the type Γ x.

                                      Instances
                                        def Imperative.StoreHasTyping {P : PureExpr} [HasVal P] (f : P.Factory) (σ : P.Ident → Option P.Val) (Γ : VarTyping P) :

                                        The store σ (a SemanticStore P) conforms to the typing Γ: every variable that Γ types holds a value of that type.

                                        Equations
                                        Instances For
                                          def Imperative.VarTyping.extend {P : PureExpr} (Γ : VarTyping P) (defs : List (P.Ident × P.Ty)) :

                                          Extend the typing Γ with the typed definitions defs; the first definition of a name wins.

                                          Equations
                                          Instances For

                                            Type soundness of the evaluator against the typing judgment.

                                            Instances
                                              class Imperative.HasInt (P : PureExpr) [HasVal P] [HasFvars P] :
                                              Type u_1

                                              Integer constants and the integer type.

                                              Instances

                                                Integer arithmetic / comparison primitives.

                                                Instances

                                                  Substitution of free variables in expressions. Used for closure capture in function declarations.

                                                  • substFvar : P.Expr → P.Ident → P.Expr → P.Expr

                                                    Substitute a single free variable with an expression

                                                  • substFvars : P.Expr → List (P.Ident × P.Expr) → P.Expr

                                                    Simultaneously substitute multiple free variables with expressions. Replaces all variables in a single pass, avoiding capture between substitutions.

                                                  • renameFvars : P.Expr → List (P.Ident × P.Ident) → P.Expr

                                                    Simultaneously rename free variables by NAME, in a single pass with first-match semantics (a ↦ b for the first (a, b) in the list, else unchanged). Unlike substFvars, this rewrites a free variable's name in place and preserves everything else about the occurrence — in particular any type annotation it carries — so renaming never drops type information the way substituting a freshly-built bare free variable would.

                                                  Instances
                                                    @[reducible, inline]

                                                    A function declaration for use with PureExpr - instantiation of Func for any expression system that implements the PureExpr interface.

                                                    Equations
                                                    Instances For