lean2js

Lean2Js.Enc

source

Imports 2

Where an ordinary Lean type sits inside Value #

eval answers with a Value, so a certificate about an author's def has to say which Value the def's result is. Enc is that correspondence: one instance per type an author may write, carrying the subset type it lands in, the encoding, and the decoding that shows the encoding does not fold two terms into one.

The entry check is not a law of the class. toValue is total and the boundary is not — Enc Int encodes every Int, including the ones past Int53 that Decl.decl_refuses turns away. So hasTy holds only of the values accepts admits, and accepts is what an author sees as a hypothesis on their shipped theorem. A type whose encoding cannot reach outside its subset type carries accepts _ _ := True and the hypothesis disappears.

Value.bigint and Value.dict are instanced in Lean2Js/Prelude.lean rather than here: both need a Lean type that is not already spoken for, since Int encodes to Int53 and List (String × α) would be an array. Value.fn gets none at all — it names a declaration, and no Lean function value knows which declaration it is.

class

Lean2Js.Enc

source
(α : Type) :

How a Lean type is carried across the boundary.

Instances
    Used by

      The scalars #

      instance

      Lean2Js.Enc.instBool

      source
      @[instance_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      Used by
        theorem

        Lean2Js.Enc.ty_bool

        source
        @[simp]
        Used by
          theorem

          Lean2Js.Enc.toValue_bool

          source
          @[simp]
          Used by
            instance

            Lean2Js.Enc.instInt

            source
            @[instance_reducible]
            Equations
            • One or more equations did not get rendered due to their size.
            Used by
              theorem

              Lean2Js.Enc.ty_int

              source
              @[simp]
              Used by
                theorem

                Lean2Js.Enc.toValue_int

                source
                @[simp]
                Used by
                  instance

                  Lean2Js.Enc.instUInt32

                  source
                  @[instance_reducible]
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Used by
                    theorem

                    Lean2Js.Enc.ty_uint32

                    source
                    @[simp]
                    Used by
                      theorem

                      Lean2Js.Enc.toValue_uint32

                      source
                      @[simp]
                      Used by
                        instance

                        Lean2Js.Enc.instString

                        source
                        @[instance_reducible]
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Used by
                          theorem

                          Lean2Js.Enc.ty_string

                          source
                          @[simp]
                          Used by
                            theorem

                            Lean2Js.Enc.toValue_str

                            source
                            @[simp]
                            Used by
                              theorem

                              Lean2Js.Enc.toValue_inj

                              source
                              {α : Type} [Enc α] {a b : α} (h : toValue a = toValue b) :
                              a = b

                              No two terms share an encoding. ofValue recovers the term, so a type's Enc already says this; what it takes to use it is naming the step.

                              Used by
                                class

                                Lean2Js.Enc.EncBEq

                                source
                                (α : Type) [Enc α] [BEq α] :

                                The types the subset compares for equality. eval compares encodings and the author writes == on their own type, so the two agree exactly when the encoding neither folds two terms together nor splits one apart. It is a class of its own rather than a law of Enc because a type with no BEq has nothing to state.

                                Instances
                                  Used by
                                    instance

                                    Lean2Js.Enc.instEncBEqOfLawfulBEq

                                    source
                                    {α : Type} [Enc α] [BEq α] [LawfulBEq α] :

                                    Injectivity is one half; the other is that both ==s decide equality rather than something coarser. An author's own type reaches this by deriving DecidableEq, which is where its LawfulBEq comes from.

                                    Used by

                                      The shapes built out of another type #

                                      instance

                                      Lean2Js.Enc.instOption

                                      source
                                      @[instance_reducible]
                                      {α : Type} [Enc α] :
                                      Enc (Option α)
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Used by

                                        The subset type is normalised the way the scalars are, because a declaration's parameter carries it as this projection. The encoding is not: nothing in the subset's own forms needs it rewritten, and what does is a match on one, whose arm has to reach the tag the pattern tests.

                                        theorem

                                        Lean2Js.Enc.ty_option

                                        source
                                        @[simp]
                                        {α : Type} [Enc α] :
                                        ty (Option α) = (ty α).option
                                        Used by
                                          theorem

                                          Lean2Js.Enc.toValue_none

                                          source
                                          {α : Type} [Enc α] :
                                          Used by
                                            theorem

                                            Lean2Js.Enc.toValue_some

                                            source
                                            {α : Type} [Enc α] (a : α) :
                                            toValue (some a) = Value.obj "some" [("value", toValue a)]
                                            Used by
                                              instance

                                              Lean2Js.Enc.instExcept

                                              source
                                              @[instance_reducible]
                                              {ε α : Type} [Enc ε] [Enc α] :
                                              Enc (Except ε α)
                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Used by
                                                theorem

                                                Lean2Js.Enc.ty_except

                                                source
                                                @[simp]
                                                {ε α : Type} [Enc ε] [Enc α] :
                                                ty (Except ε α) = (ty α).result (ty ε)
                                                Used by
                                                  theorem

                                                  Lean2Js.Enc.toValue_ok

                                                  source
                                                  {ε α : Type} [Enc ε] [Enc α] (a : α) :
                                                  Used by
                                                    theorem

                                                    Lean2Js.Enc.toValue_error

                                                    source
                                                    {ε α : Type} [Enc ε] [Enc α] (e : ε) :
                                                    Used by
                                                      theorem

                                                      Lean2Js.Enc.hasFieldTys_cons_of

                                                      source
                                                      (p : Core.Program) (key : String) (v : Value) (ty : Core.Ty) (rest : List (String × Value)) (tys : List (String × Core.Ty)) (hv : Value.hasTy p v ty = true) (hrest : Value.hasFieldTys p rest tys = true) :
                                                      Value.hasFieldTys p ((key, v) :: rest) ((key, ty) :: tys) = true

                                                      One field of an object, checked against one field of the declared type. The value and its type are taken as they are rather than through Enc, which is what a field whose type is the one being declared needs: that type has no instance yet where its own encoding is being written.

                                                      Used by
                                                        theorem

                                                        Lean2Js.Enc.hasFieldTys_toValue

                                                        source
                                                        (p : Core.Program) (key : String) {α : Type} [Enc α] (x : α) (rest : List (String × Value)) (tys : List (String × Core.Ty)) (hx : accepts p x) (hrest : Value.hasFieldTys p rest tys = true) :
                                                        Value.hasFieldTys p ((key, toValue x) :: rest) ((key, ty α) :: tys) = true

                                                        One field of a constructor, for the instance a deriving Enc writes: the entry check on an object is the checks on its fields, and each field's is its own Enc's.

                                                        Used by
                                                          instance

                                                          Lean2Js.Enc.instList

                                                          source
                                                          @[instance_reducible]
                                                          {α : Type} [Enc α] :
                                                          Enc (List α)
                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Used by
                                                            theorem

                                                            Lean2Js.Enc.ty_list

                                                            source
                                                            @[simp]
                                                            {α : Type} [Enc α] :
                                                            ty (List α) = (ty α).array
                                                            Used by
                                                              theorem

                                                              Lean2Js.Enc.toValue_list

                                                              source
                                                              @[simp]
                                                              {α : Type} [Enc α] (xs : List α) :
                                                              Used by