Skip to content

Commit efe8790

Browse files
Simplify terms in function-composition-part-1 design doc (#802)
* Simplify terms in function-composition-part-1 design doc Use names for models instead of "model 1" and "model 2" * Update exploration/function-composition-part-1.md Co-authored-by: Addison Phillips <[email protected]> * Update exploration/function-composition-part-1.md Co-authored-by: Addison Phillips <[email protected]> * Rename simple model to formatted value model, per Addison's suggestion --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent b4fd5a6 commit efe8790

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

exploration/function-composition-part-1.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ abstract "input" and "output" types.
469469
Returning to Example Y1, consider two possible models
470470
of the runtime behavior of function composition.
471471

472-
**Model 1:**
472+
#### Preservation Model
473+
474+
This model preserves the options in the result of the function.
473475

474476
1. Evaluate `$num` to a value and pass it to the `:number` function,
475477
along with named options `{"maxFrac": "2"}`
@@ -494,7 +496,10 @@ of the runtime behavior of function composition.
494496

495497
then the formatted result is "0.33 0.33333".
496498

497-
**Model 2:**
499+
#### Formatted Value Model
500+
501+
This model preserves the formatted value of the function,
502+
but not the options that were passed to the function.
498503

499504
1. Evaluate `$num` to a value and pass it to the `:number` function,
500505
along with named options `{"maxFrac": "2"}`
@@ -512,10 +517,12 @@ then the formatted result is "0.33 0.33333".
512517

513518
then the formatted result is "0.33 0.33".
514519

520+
#### Comparison between models
521+
515522
The difference is in step 2: whether the implementation
516523
of the `number` function returns a value encapsulating
517-
the various options that were passed in (model 1),
518-
or only a formatted result (model 2).
524+
the various options that were passed in (preservation model),
525+
or only a formatted result (formatted value model).
519526

520527
In terms of implementation, the result depends on
521528
what the nature is of the value that is bound to
@@ -529,10 +536,10 @@ before a function call.
529536
Still, whatever value is stored in the environment
530537
must capture as much information as is needed by functions.
531538

532-
In Model 2, the value is a simple "formatted value",
539+
In the formatted value model, the value is a simple "formatted value",
533540
analogously to MessageFormat 1.
534541

535-
In Model 1, it is a more structured value that captures
542+
In the preservation model, it is a more structured value that captures
536543
both the "formatted value", and everything that was used to construct it,
537544
as in the first model.
538545

@@ -546,7 +553,7 @@ A "resolved value"
546553
is also the operand of a function.
547554

548555
Another way to resolve the ambiguity between
549-
Models 1 and 2 is to ask
556+
the simple and the preservation model is to ask
550557
when two resolved values are the same
551558
and when they are different.
552559

@@ -597,7 +604,7 @@ interchangeable in any further piece of the message
597604
that follows this fragment.
598605
No processing can distinguish the resolved values
599606
of the two variables.
600-
This corresponds to model 1.
607+
This corresponds to the formatted value model.
601608

602609
Interpretation 2: The meaning of `$x` is
603610
a value that represents
@@ -608,7 +615,7 @@ If the resolved value of `$x`, V, is passed to another function,
608615
that function can distinguish V from another value V1
609616
that represents the same formatted string,
610617
with different options.
611-
This corresponds to model 2.
618+
This corresponds to the preservation model.
612619

613620
The choice of interpretation affects the meaning of
614621
function composition,
@@ -752,14 +759,14 @@ as both are "resolved values" according to the spec.
752759
But both interpretation 1 and interpretation 2 complicate that.
753760

754761
Alternative 1: A function returns a "formatted value".
755-
This matches model 1, where formatted values
762+
This matches the formatted value model, where formatted values
756763
are bound to names.
757764

758765
Alternative 2: A function returns a composite value
759766
that conceptually pairs a base value (possibly the
760767
operand of the function, but possibly not; see Example B1)
761768
with options.
762-
This matches model 2.
769+
This matches the preservation model.
763770
If we preserve the single usage of "resolved value"
764771
in the spec, this implies that the (base value, options)
765772
representation applies to all resolved values,
@@ -783,8 +790,8 @@ There seem to be several areas of ambiguity:
783790

784791
* Are named values essentially `FormattedValue`s,
785792
or do they have additional structure that is used
786-
internally in the formatter? (Model 1 vs. Model 2)
787-
* In Model 2, some functions "look back" for the original value,
793+
internally in the formatter? (formatted value model vs. preservation model)
794+
* In the preservation model, some functions "look back" for the original value,
788795
(like `number`)
789796
while others return a new "source value"
790797
(like `getAge` in Example B1).
@@ -801,12 +808,15 @@ The question is how to craft the spec in a way that is consistent with expectati
801808

802809
## Requirements
803810

804-
In the rest of this document, we assume some version of Model 2.
805-
However, if Model 1 is more desired, the questions arise of how to
811+
In the rest of this document, we assume some version of
812+
the preservation model.
813+
However, if the formatted value model is more desired,
814+
the questions arise of how to
806815
forbid compositions of functions that would do surprising things
807816
under that model.
808817

809-
Even under Model 2, some instances of composition won't make sense,
818+
Even under the preservation model, some instances of composition
819+
won't make sense,
810820
so we need to define the error behavior when it doesn't make sense.
811821

812822
This implies that we need:

0 commit comments

Comments
 (0)