Substitution¶
Substitution replaces variables with terms without capture: a free name in the replacement must not be bound by an inner binder. Telescope instantiation applies the same rule to dependent parameters, where replacing one index can change the types of later arguments.
substitution
¶
Capture-free substitution and telescope instantiation for QIEC.
StaticSubstitution
didactic-model
¶
StaticSubstitution(*, types: tuple[tuple[str, TypeExpr | TypeRow], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), indices: tuple[tuple[str, IndexTerm], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), effects: tuple[tuple[str, EffectRef | EffectVariable], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), rigid: tuple[tuple[StaticVariableId, StaticArgument], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), effect_rows: RowSubstitution = field(default=RowSubstitution(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
A deterministic substitution split by static namespace.
| PARAMETER | DESCRIPTION |
|---|---|
types
|
Bindings from type-variable names to types, and from row-variable names to rows.
TYPE:
|
indices
|
Bindings from index-variable names to index terms.
TYPE:
|
effects
|
Bindings from effect-variable names to interface applications or other effect variables.
TYPE:
|
rigid
|
Bindings by stable identity. The evaluator supplies these when a selected case branch reveals actual constructor arguments. Declaration instantiations leave this empty.
TYPE:
|
effect_rows
|
Bindings for the open tails of effect rows, which a call makes when a function argument's row instantiates the row of a function-typed parameter.
TYPE:
|
at_identity
¶
at_identity(identity: StaticVariableId) -> StaticArgument | None
Look up the runtime argument of a rigid variable.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
The stable identity bound by a checked case branch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StaticArgument or None
|
The selected static argument, if this substitution binds it. |
Source code in src/quivers/qiec/substitution.py
type
¶
What a type or row binder of this name is bound to.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeExpr or TypeRow or None
|
The bound type or row, or None when this substitution says nothing about the name, in which case the variable stands. |
Source code in src/quivers/qiec/substitution.py
index
¶
index(name: str) -> IndexTerm | None
What an index binder of this name is bound to.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IndexTerm or None
|
The bound index, or None when the name is unbound here. |
Source code in src/quivers/qiec/substitution.py
effect
¶
effect(name: str) -> EffectRef | EffectVariable | None
What an effect binder of this name is bound to.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The binder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectRef or EffectVariable or None
|
The bound interface application or effect variable, or None when the name is unbound here. |
Source code in src/quivers/qiec/substitution.py
instantiate_telescope
¶
instantiate_telescope(telescope: Telescope, arguments: tuple[StaticArgument, ...]) -> StaticSubstitution
Kind-check static arguments and construct their substitution.
| PARAMETER | DESCRIPTION |
|---|---|
telescope
|
The binders to instantiate, in order. Later binders may depend on earlier ones, so the arguments are checked left to right with the substitution built so far already applied.
TYPE:
|
arguments
|
One argument per binder.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StaticSubstitution
|
The substitution carrying each binder to its argument. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If an argument is of the wrong static class for its binder. |
ValueError
|
If the counts differ, or an argument is of the wrong kind or index sort. |
Source code in src/quivers/qiec/substitution.py
substitute_index
¶
substitute_index(term: IndexTerm, substitution: StaticSubstitution) -> IndexTerm
Substitute into an index term.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The index to rewrite.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IndexTerm
|
The rewritten index. A branch variable can only be substituted by its rigid identity, independently of its displayed name. |
Source code in src/quivers/qiec/substitution.py
substitute_effect
¶
substitute_effect(effect: EffectRef, substitution: StaticSubstitution) -> EffectRef
Substitute into an interface application's static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
effect
|
The application to rewrite.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectRef
|
The application with its arguments rewritten. The declaration's identity and name are unchanged, since substitution instantiates an interface rather than selecting a different one. |
Source code in src/quivers/qiec/substitution.py
substitute_plate
¶
substitute_plate(plate: PlateShape, substitution: StaticSubstitution) -> PlateShape
Substitute static variables in a plate's axis sizes.
| PARAMETER | DESCRIPTION |
|---|---|
plate
|
The plate.
TYPE:
|
substitution
|
The static substitution.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PlateShape
|
The plate with every axis size substituted. |
Source code in src/quivers/qiec/substitution.py
substitute_type
¶
substitute_type(type_: TypeExpr, substitution: StaticSubstitution) -> TypeExpr
Substitute into a type expression.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The type to rewrite.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeExpr
|
The rewritten type. Only an identity binding can replace a rigid type variable. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the expression is of an unknown class. |
Source code in src/quivers/qiec/substitution.py
substitute_type_row
¶
substitute_type_row(row: TypeRow, substitution: StaticSubstitution) -> TypeRow
Substitute into a row's types and instantiate its tail.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
The row to rewrite.
TYPE:
|
substitution
|
The bindings to apply. A binding for the tail's name replaces the tail by the entries and tail of the row it is bound to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeRow
|
The rewritten row. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the tail is bound to something other than a row. |
ValueError
|
If the tail's instantiation repeats a label the row names, which the row's well-formedness says its tail lacks. |
Source code in src/quivers/qiec/substitution.py
substitute_predicate
¶
substitute_predicate(predicate: RowPredicate, substitution: StaticSubstitution) -> RowPredicate
Substitute into the rows a row predicate relates.
| PARAMETER | DESCRIPTION |
|---|---|
predicate
|
The predicate.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RowPredicate
|
The predicate over the substituted rows. |
Source code in src/quivers/qiec/substitution.py
match_function_rows
¶
match_function_rows(expected: tuple[TypeExpr, ...], actual: tuple[TypeExpr, ...]) -> RowSubstitution
The effect-row instantiation function arguments make at a call.
A parameter of type A -> B !{e | r} given a function whose row
is {e, s} instantiates r to {s}, so a higher-order
computation performs the row of the function it is given.
| PARAMETER | DESCRIPTION |
|---|---|
expected
|
The callee's parameter types, at the call's static arguments.
TYPE:
|
actual
|
The arguments' types.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RowSubstitution
|
A binding for each open tail of a function-typed parameter whose argument determines it; empty when there is none. |
Source code in src/quivers/qiec/substitution.py
substitute_static
¶
substitute_static(term: StaticArgument, substitution: StaticSubstitution) -> StaticArgument
Substitute into a static argument of any namespace.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A type, index, or effect argument.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StaticArgument
|
The rewritten argument, dispatched to the namespace it belongs to. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the term is of an unknown class. |
Source code in src/quivers/qiec/substitution.py
substitute_row
¶
substitute_row(row: EffectRow, substitution: StaticSubstitution) -> EffectRow
Substitute into every interface application in an effect row.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
The row to rewrite.
TYPE:
|
substitution
|
The bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectRow
|
The row with each entry's interface rewritten and, when the substitution binds the open tail in its effect rows, the tail resolved. Instance identities are untouched. |
Source code in src/quivers/qiec/substitution.py
instantiate_operation
¶
instantiate_operation(operation: OperationDef, arguments: tuple[StaticArgument, ...], outer: StaticSubstitution = StaticSubstitution()) -> tuple[tuple[TypeExpr, ...], TypeExpr]
Instantiate an operation's signature at a request site.
| PARAMETER | DESCRIPTION |
|---|---|
operation
|
The declared operation.
TYPE:
|
arguments
|
Static arguments for the operation's own telescope.
TYPE:
|
outer
|
Bindings already in force from the interface's telescope. These come first, so an operation binder of the same name shadows the interface's, which is the scoping a reader expects.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[TypeExpr, ...], TypeExpr]
|
The instantiated parameter types and result type. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If an argument is of the wrong static class for its binder. |
ValueError
|
If the argument count is wrong, or an argument is ill-kinded. |
Source code in src/quivers/qiec/substitution.py
substitute_evidence
¶
substitute_evidence(evidence: EqualityEvidence, substitution: StaticSubstitution) -> EqualityEvidence
Substitute into the equality an evidence term states.
| PARAMETER | DESCRIPTION |
|---|---|
evidence
|
The evidence to rewrite.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EqualityEvidence
|
Evidence of the same class stating the substituted equality. A branch given keeps its identity, since substituting into what it proves does not make it a different piece of evidence. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the evidence is of an unknown class. |
Source code in src/quivers/qiec/substitution.py
substitute_value
¶
substitute_value(value: Value, substitution: StaticSubstitution) -> Value
Substitute static arguments throughout a value term.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value to rewrite.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Value
|
The value with every type, index, and effect position substituted. Value-level structure is untouched: this rewrites the static layer, not the data. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the value is of an unknown class. |
Source code in src/quivers/qiec/substitution.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
substitute_local
¶
substitute_local(local: Local, substitution: StaticSubstitution) -> Local
Substitute into a local's type.
| PARAMETER | DESCRIPTION |
|---|---|
local
|
The binder.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Local
|
The binder at its substituted type. |
Source code in src/quivers/qiec/substitution.py
substitute_lambda
¶
substitute_lambda(function: Lambda, substitution: StaticSubstitution) -> Lambda
Substitute static arguments throughout a function value.
| PARAMETER | DESCRIPTION |
|---|---|
function
|
The function.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Lambda
|
The function with its parameter, body, and type substituted; its code identity and origin are unchanged. |
Source code in src/quivers/qiec/substitution.py
substitute_request
¶
substitute_request(request: EffectRequest, substitution: StaticSubstitution) -> EffectRequest
Substitute static arguments throughout an effect request.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The request to rewrite.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectRequest
|
The request against the substituted interface application, with its own static and value arguments and result type rewritten. The instance, the operation, and the site are identities and do not move. |
Source code in src/quivers/qiec/substitution.py
substitute_computation
¶
substitute_computation(computation: Computation, substitution: StaticSubstitution) -> Computation
Substitute static arguments throughout a computation.
Declaration parameters are replaced by name. Constructor skolems
carry derived StaticVariableIds, so substituting for a declaration
binder cannot capture a branch variable with the same name. The
evaluator can additionally replace the selected branch's skolems by
identity. That substitution leaves other branches' binders and the
named binders of case motives in scope.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The computation to rewrite.
TYPE:
|
substitution
|
The static bindings to apply.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Computation
|
The computation with every static position substituted. Identities are preserved throughout: a call still names the same callee, a handle the same handler, and an allocation the same instance. An empty substitution returns the immutable graph itself. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the computation, or a term nested in it, is of an unknown class. |
Source code in src/quivers/qiec/substitution.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | |