act icon indicating copy to clipboard operation
act copied to clipboard

Container abstractions: arrays, mappings, ....

Open MrChico opened this issue 6 years ago • 0 comments

In many cases, we want specifications to be expressed in terms of the various containers present in the source language. Such containers include at least the following:

  • Arrays
  • Mappings (n.b. that an Array can be represented as a mapping whose keys are integers and with an additional entry keeping it's length) but future version may also include abstractions for structs / tuples (products) and enums / abstract data types (coproducts) of appropriate types.

Of course, there are lots of possibilities here as far as syntax is concerned, but generally, we want to support at least:

  • map (a.k.a. fmap), applying a function to all the containers values.
  • reduce (a.k.a. fold, accumulate...), applying a function to a container recursively, aggregating the result.

Some conveniences like sum, length and slice would also be nice.

To keep things practical, I suggest we only consider containers that are supported in the ABIEncoder for now. For specificity, I'll keep a list below of supported HLL functions. In the following, container(A) denotes a container (array or mapping), whose type of values is A.

  • map : container(A) -> (A -> B) -> container(B)
  • reduce: container(A) -> (A -> A -> A) -> A
  • Lambda abstractions
  • Conveniences: length, sum, product, slice, reduce (overloaded to also take index)

MrChico avatar Nov 25 '19 18:11 MrChico