Effect4

R4: State: the world types every cell at any type, with rows as templatesreq:R4

Requirement R4: Stateful memory and row templatesabout:req:R4

This page explains requirement R4 in Effect4. It covers what the requirement asks for mutable cells and row templates, why stateful typing matters, and how the property is checked.

What the requirement asksabout:req:R4:what-it-asks

Requirement R4 demands that the typed world supports mutable cells at arbitrary types and models operation rows as templates (docs/core/system-map.md §8):

  • World typing: World explicitly tracks types for cells (w.Ρ), deferred promises (w.Π), fibers (w.Γ), and tokens (w.Θ).
  • Row templates: operation rows act as templates whose type parameters instantiate via match by bounds.
  • Binder terms: function rows take first-order binder terms that map cell types under environment extensions.

Allocating a fresh cell or promise must extend the world monotonically without invalidating earlier allocations.

Why it mattersabout:req:R4:why-it-matters

Concurrent programs coordinate across fibers using shared mutable state, asynchronous promises, and synchronized queues.

If stateful references supported only primitive numbers or hard-coded payload types, applications could not manage complex state.

Matching row templates by bounds lets a generic operation take its type arguments from the program, before the run.

How it is checkedabout:req:R4:how-it-is-checked

The requirement is checked by proving world extension, template matching, and step typing theorems:

  • World order reflexivity and transitivity are stated in src/Effect4/Laws/Program/Typed/World.lean.
  • Allocation monotonicity is stated by refMake_extension and deferredMake_extension in the same file.
  • Totality of template matching by bounds is stated by Bounds.matchB_complete (src/Effect4/Laws/Program/Bounds.lean).
  • Atomic update typing is stated by fold_typed_atomic_update (src/Effect4/Laws/Program/Typed/ListFold.lean).

The plan on this page gives each theorem's status and the goals it rests on.

atomicmodulocommittedmodulocountedmodulocleans_oncemoduloshop_stagesgoallog_debitsgoal
The open part of R4: its planned goals and the theorems proved modulo them. An arrow goes from a node to a node its proof reaches first.
The figure in words
R4 by concept: each concept its nodes are placed at, by tag or by module. An arrow goes where a node's proof reaches a node of another concept.
The figure in words
NodeStatusRests onNearest nodes
order_reflproved——
order_transproved——
refMake_extensionproved——
deferredMake_extensionproved——
memoBuild_extensionproved——
fold_typed_atomic_updateproved—readTerm_printTerm, order_refl, termMaps_of_typed, listOf_upper, fits_subN, fits_normalize, normalize_idem, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty
handle_identity_lawsproved—fits_mono
saved_mask_image_membershipproved——
scoped_body_substitution_boundaryproved—denotesTyped, scopeParams_child, at_child, fits_subN, listOf_upper, fits_normalize, normalize_idem, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty, at_append
awaitStep_typesproved—typed
Latch.Model.closeStep_typesproved—typed
flushStep_typesproved—typed
initialStep_typesproved—typed
isOpenStep_typesproved—typed
wakeStep_typesproved—typed
Latch.Model.withdrawStep_typesproved—typed
image_agreesproved——
afterExit_firstproved—raceCompleteFirst_accepts
typedproved—candsList_nil, cands_var, candsList_cons, types_ascribe, normalize_idem, subN_refl, matchArgsB_list_var_nat, matchArgsB_append, matchArgsB_cons_nil, lift_member, matchArgsB_one_var, matchArgsB_two_vars, join_eq_right_of_subN, matchArgsB_ite
ascribe_untypedproved——
step_keeps_cellproved—fold_typed_atomic_update
types_ascribeproved—lift_member, normalize_idem
available_typesproved—typed
PartitionedSemaphore.initial_typesproved—typed
reserve_typesproved—typed
tryTake_typesproved—typed
Pool.Model.closeStep_typesproved—typed
drainStep_typesproved—typed
Model.initial_typesproved—matchArgsB_cons_nil, matchArgsB_append
leaseStep_typesproved—typed
lease_enrols_iffproved——
Pool.Model.profile_closedproved——
returnStep_typesproved—typed
selectStep_typesproved—typed
Pool.Model.withdrawStep_typesproved—typed
close_answersproved—Pool.Model.withdrawStep_types, check_complete, check_sound, drainStep_types, matchB_modify_use, matchB_refOf_var, waitRetryAt_answers, mask_printed_form_profile, subN_refl, lift_member, normalize_idem, matchArgsB_two_vars, matchArgsB_list_var_nat, optionTy_option, selectStep_types, Pool.Model.closeStep_types
Pool.make_typesproved—normalize_idem, check_complete, check_sound, close_answers, Model.initial_types, matchB_one_var
use_typesproved—check_complete, check_sound, subN_refl, lift_member, normalize_idem, matchArgsB_two_vars, matchArgsB_list_var_nat, optionTy_option, selectStep_types, matchB_modify_use, matchB_refOf_var, returnStep_types, Pool.Model.withdrawStep_types, leaseStep_types, waitRetryAt_answers, protectedBy_has
ascribe_scopedproved——
argsproved—noApp_args
headproved——
above_argsproved—mem_zip_map_right, instance_shape
above_prodproved——
admits_normalizeproved—normalize_idem
below_argsproved——
candsFields_eqproved——
candsItems_eqproved——
candsList_belowproved—cands_below
candsList_consproved——
candsList_nilproved——
cands_argsproved—candsItems_eq, candsFields_eq, comp_inv, comp_co
cands_belowproved—args, comp_ne_contra, cands_args, below_args, cands_union_right, cands_mem_members, head, cands_var
cands_mem_membersproved—cands_union_right
cands_union_rightproved——
cands_varproved——
comp_coproved——
comp_invproved——
comp_ne_contraproved—comp_inv, comp_co
coversproved—above_args, above_prod, prod_or_not, recovers, cands_args, args, below_args, cands_union_right, head, cands_var
instance_shapeproved——
instantiate_solveproved—lookup_added
joinCands_leastproved—subN_join_least, subN_never
joinCands_upperproved—normalize_idem, subN_trans, subN_refl
join_eq_left_of_subNproved—join_eq_right_of_subN
join_eq_right_of_subNproved—normalize_idem, subN_refl, subN_join_least
lookup_addedproved—lowers_cons
lookup_solve_seedproved——
lowers_consproved——
matchArgsB_appendproved—candsList_nil, cands_var, candsList_cons
matchArgsB_completeproved—covers, candsList_below, solve_between
matchArgsB_cons_nilproved—candsList_nil, cands_var, candsList_cons
matchArgsB_iteproved—normalize_idem, candsList_nil, cands_var, candsList_cons
matchArgsB_leastproved—candsList_below, solve_between
matchArgsB_list_var_natproved—candsList_nil, cands_var, candsList_cons
matchArgsB_one_varproved—cands_var, candsList_nil, candsList_cons
matchArgsB_soundproved——
matchArgsB_two_varsproved—candsList_nil, cands_var, candsList_cons
matchArgsN_completeproved—admits_normalize, matchArgsB_complete
matchArgsN_leastproved—admits_normalize, matchArgsB_least
matchB_cell_fixedproved—matchB_sound
matchB_completeproved—covers, cands_below, solve_between
matchB_leastproved—cands_below, solve_between
matchB_modify_useproved—cands_var
matchB_one_varproved—cands_var
matchB_refOf_varproved—cands_var, comp_inv
matchB_soundproved—lookup_solve_seed
matchN_congrproved——
mem_lowersproved——
mem_varsOf_argsproved——
mem_zip_map_rightproved——
mem_zip_self_mapproved——
noAppFields_eq_allproved——
noAppItems_eq_allproved——
noApp_argsproved—noAppItems_eq_all, noAppFields_eq_all
prod_left_candsproved—head, args, cands_var, cands_mem_members, prod_member_left
prod_member_leftproved——
prod_member_rightproved——
prod_or_notproved——
prod_right_candsproved—head, args, cands_var, cands_mem_members, prod_member_right
recoversproved—mem_zip_self_map, cands_args, instance_shape, mem_varsOf_args, prod_right_cands, prod_left_cands, args, prod_or_not, head, cands_var
solve_betweenproved—joinCands_upper, lookup_solve_seed, mem_lowers, joinCands_least, instantiate_solve
subN_join_leastproved—normalize_idem
subN_neverproved——
templateOK_ofproved——
loop_sync_opproved—native_sync_op, iteration_below_budget, loop_of_iteration
native_sync_answerproved—native_sync_op
native_sync_opproved——
perform_scoped_iffproved——
heap_sites_keepproved—at_append, mem_addresses_iff, evaluatePrim_producer, closeOrder_eq, driveState_lift
withParams_defOfproved——
withParams_of_noneproved——
withParams_paramproved——
withParams_serviceTyproved——
admitted_heap_historyproved—evaluatePrim_producer, closeOrder_eq, at_append, mem_addresses_iff, driveState_lift
monoproved—order_trans
invoke_armproved—normalize_idem, fits_mono, fits_subN, order_trans, at_child, scopeParams_below, listOf_upper, fits_normalize, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty, scopeParams_body, withParams_defOf
param_armproved—normalize_idem, fits_mono, fits_subN, order_trans, listOf_upper, fits_normalize, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty, scopeParams_decl, withParams_param
scopeParams_refproved——
syncRow_typedproved—fits_normalize, subN_trans, fits_subN, termMaps_of_typed, matchB_sound, hom_eq_cata_ty, errOf_payload, isPayload_of_hasTy_record, normalize_idem, subN_refl
termMaps_of_typedproved—listOf_upper, fits_subN, fits_normalize, normalize_idem, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty, fits_mono
scopeParams_belowproved——
scopeParams_bodyproved——
scopeParams_childproved——
scopeParams_declproved——
scopeParams_layer_belowproved——
PubSub.initial_typesproved—typed
PubSub.poll_typesproved—typed
slide_typesproved—typed
subscribe_typesproved—typed
tryPublish_typesproved—typed
unsubscribe_typesproved—typed
ascribe_formed_for_stepsproved——
empty_typedproved——
message_nodes_for_stepsproved——
offerStep_typedproved—offerStep_types
offerStep_typesproved—offer_nodes_for_steps, message_nodes_for_steps, ascribe_formed_for_steps, typed
offer_nodes_for_stepsproved—message_nodes_for_steps
pollStep_typedproved—pollStep_types
pollStep_typesproved—offer_nodes_for_steps, message_nodes_for_steps, ascribe_formed_for_steps, typed
sizeStep_typedproved—typed
takeStep_typedproved—Queue.Model.takeStep_types
Queue.Model.takeStep_typesproved—offer_nodes_for_steps, message_nodes_for_steps, ascribe_formed_for_steps, typed
withdrawOffer_typedproved—withdrawOffer_types
withdrawOffer_typesproved—typed
withdrawTake_typedproved—withdrawTake_types
withdrawTake_typesproved—typed
bounded_typesproved—empty_typed, offer_nodes_for_steps, message_nodes_for_steps, matchB_one_var, check_complete, check_sound
offer_typesproved—withdrawOffer_types, check_complete, check_sound, optionTy_option, lift_member, normalize_idem, subN_refl, matchArgsB_two_vars, matchArgsB_list_var_nat, offerStep_types, matchB_modify_use, matchB_refOf_var, rowTy_instantiated_formed, mask_printed_form_profile, offer_nodes_for_steps, message_nodes_for_steps
Queue.poll_typesproved—check_complete, check_sound, lift_member, normalize_idem, subN_refl, matchArgsB_two_vars, matchArgsB_list_var_nat, optionTy_option, pollStep_types, offer_nodes_for_steps, message_nodes_for_steps, matchB_modify_use, matchB_refOf_var
size_typesproved—lift_member, normalize_idem, check_complete, check_sound, offer_nodes_for_steps, message_nodes_for_steps, matchB_refOf_var
Queue.take_typesproved—withdrawTake_types, check_complete, check_sound, optionTy_option, lift_member, normalize_idem, subN_refl, matchArgsB_two_vars, matchArgsB_list_var_nat, Queue.Model.takeStep_types, offer_nodes_for_steps, message_nodes_for_steps, matchB_modify_use, matchB_refOf_var, waitRetryAt_answers, mask_printed_form_profile
modify_callback_answersproved—typed, check_complete, check_sound, matchB_modify_use, matchB_refOf_var
empty_typesproved——
Semaphore.Model.profile_closedproved——
releaseStep_typesproved—typed
takeIfAvailableStep_typesproved—typed
Semaphore.Model.takeStep_typesproved—typed
visitStep_typesproved—typed
Semaphore.Model.withdrawStep_typesproved—typed
Semaphore.make_typesproved—empty_types, matchB_one_var, check_complete, check_sound
release_typesproved—check_complete, check_sound, normalize_idem, subN_refl, lift_member, matchArgsB_two_vars, optionTy_option, visitStep_types, matchB_modify_use, matchB_refOf_var, matchArgsB_one_var, releaseStep_types
takeIfAvailable_typesproved—takeIfAvailableStep_types, check_complete, check_sound, matchB_modify_use, matchB_refOf_var
Semaphore.take_typesproved—Semaphore.Model.withdrawStep_types, check_complete, check_sound, Semaphore.Model.takeStep_types, matchB_modify_use, matchB_refOf_var, waitRetryAt_answers, mask_printed_form_profile
withPermitsIfAvailable_typesproved—release_types, check_sound, check_complete, normalize_idem, matchArgsB_one_var, takeIfAvailable_types, protectedBy_has, sub_antisymm_canonical
withPermits_typesproved—release_types, Semaphore.Model.withdrawStep_types, check_complete, check_sound, Semaphore.Model.takeStep_types, matchB_modify_use, matchB_refOf_var, waitRetryAt_answers, protectedBy_has
fromDefinitions_declarationsproved——
arrayBatch_answersproved—modify_callback_answers
raceCompleteFirst_acceptsproved——
raceCompleteFirst_keepsproved——
get_answersproved—lift_member, normalize_idem, matchB_refOf_var, check_complete, check_sound
make_answersproved—check_complete, check_sound, Semaphore.make_types, matchB_one_var
modify_answersproved—lift_member, normalize_idem, modify_callback_answers, withPermits_types
shop_stagesgoalshop_stagescheckInput_eq_none_iff
atomicmodulolog_debits, shop_stagesunsuspended_runs, cleans_once, committed, counted, bounded, checkInput_eq_none_iff
boundedproved—history, build_retains, checkInput_eq_none_iff, mem_addresses_iff, heap_sites_keep
committedmoduloshop_stageshistory, build_retains, checkInput_eq_none_iff, shop_stages
countedmoduloshop_stageshistory, build_retains, checkInput_eq_none_iff, shop_stages
readTerm_printTermproved——
listOf_upperproved—list_eliminator, normalize_idem, subN_trans, subN_refl, extendAll_upper
fits_subNproved—subN_trans, fits_normalize
fits_normalizeproved—subN_trans, normalize_idem
normalize_idemproved——
lift_soundproved—lift_transfer
subN_transproved——
causeInputError_upperproved—cause_upper, cause_mono, normalize_idem, subN_trans, subN_refl, UnionRule.lift_upper, subN_causeOf_causeUpper, subN_exitOf_causeUpper, extendAll_eq_some_iff
hom_eq_cata_typroved——
fits_monoproved——
denotesTypedproved—provideLayerArm, at_child, subN_refl, fits_subN, fits_normalize, fiberTy_upper, scopeParams_child, hom_eq_cata_ty, subN_trans, matchB_sound, syncRow_typed, withParams_of_none, listOf_upper, normalize_idem, lift_sound, causeInputError_upper, matchArgsB_sound, errOf_payload, isPayload_of_hasTy_record, satisfies_weaken, subN_never, fits_mono, order_trans, invoke_arm, optionTy_upper, withParams_serviceTy, scopeParams_below, exitOf_upper, fits_scope_inv, param_arm, call_arm
at_childproved—at_append
at_appendproved——
subN_reflproved——
lift_memberproved——
check_completeproved——
check_soundproved——
waitRetryAt_answersproved—check_complete, check_sound, optionTy_option, normalize_idem, matchArgsB_one_var
mask_printed_form_profileproved—saved_mask_restoration, read_print, check_sound, check_complete
optionTy_optionproved—lift_member
protectedBy_hasproved—normalize_idem, check_sound, check_complete, mask_printed_form_profile
iteration_below_budgetproved——
loop_of_iterationproved——
mem_addresses_iffproved—yieldAt_addressYield, mem_foldList_iff, addresses_eq_foldList
evaluatePrim_producerproved——
closeOrder_eqproved——
driveState_liftproved——
errOf_payloadproved——
isPayload_of_hasTy_recordproved—handles_of_payloadFieldTy
rowTy_instantiated_formedproved——
sub_antisymm_canonicalproved——
checkInput_eq_none_iffproved——
unsuspended_runsproved—run_agrees
cleans_oncemodulolog_debitshistory, build_retains, checkInput_eq_none_iff, replace_sum, mem_addresses_iff, at_append, closeOrder_eq, evaluatePrim_producer, replace_sum_le_omitted, driveState_lift, starts_le_pushes, log_debits
historyproved—reached_history
build_retainsproved—finishBuild_retains, checkInput_eq_none_iff
list_eliminatorproved—subN_list_iff, normalize_idem, subN_trans, subN_refl
extendAll_upperproved—extendAll_adjoint
lift_transferproved—joinAll_keeps, mapM_answer
cause_upperproved—subN_causeOf_causeUpper, subN_exitOf_causeUpper
cause_monoproved—subN_exitOf_iff, subN_causeOf_causeUpper, subN_trans, subN_causeOf_iff
UnionRule.lift_upperproved—le_joinAll, subN_trans, mapM_answer
subN_causeOf_causeUpperproved——
subN_exitOf_causeUpperproved—subN_trans, subN_refl, subN_exitOf_iff
extendAll_eq_some_iffproved——
provideLayerArmproved—fits_subN, subN_refl, fits_normalize, fiberTy_upper, scopeParams_child, at_child, hom_eq_cata_ty, subN_trans, matchB_sound, syncRow_typed, withParams_of_none, listOf_upper, normalize_idem, lift_sound, causeInputError_upper, matchArgsB_sound, errOf_payload, isPayload_of_hasTy_record, satisfies_weaken, subN_never, fits_mono, order_trans, fits_scope_inv
fiberTy_upperproved—fiber_eliminator, normalize_idem, subN_trans, subN_refl, extendAll_upper
satisfies_weakenproved——
optionTy_upperproved—option_eliminator, normalize_idem, subN_trans, subN_refl, Eliminator.lift_upper
exitOf_upperproved—exit_eliminator, normalize_idem, subN_trans, subN_refl, extendAll_upper
fits_scope_invproved——
call_armproved—fits_mono, fits_subN, normalize_idem, order_trans, listOf_upper, fits_normalize, lift_sound, subN_trans, causeInputError_upper, matchArgsB_sound, hom_eq_cata_ty, scopeParams_body, withParams_of_none
saved_mask_restorationproved—at_append
read_printproved—readTerm_printTerm
yieldAt_addressYieldproved——
mem_foldList_iffproved—exists_at_of_mem_foldList
addresses_eq_foldListproved——
handles_of_payloadFieldTyproved——
run_agreesproved—run_eq_meaning
replace_sumproved——
replace_sum_le_omittedproved—replace_sum
starts_le_pushesproved—funded_reachable
log_debitsgoallog_debitscheckInput_eq_none_iff
reached_historyproved——
finishBuild_retainsproved—checkInput_eq_none_iff
subN_list_iffproved——
extendAll_adjointproved—adjoint, extendAll_eq_some_iff
joinAll_keepsproved—foldl_keeps
mapM_answerproved—mapM_cons_eq_some
subN_exitOf_iffproved——
subN_causeOf_iffproved——
le_joinAllproved—joinAll_keeps
fiber_eliminatorproved—subN_fiberOf_iff, normalize_idem, subN_trans, subN_refl
option_eliminatorproved—subN_option_iff, normalize_idem, subN_trans, subN_refl
Eliminator.lift_upperproved—subN_refl, UnionRule.lift_upper
exit_eliminatorproved—subN_exitOf_iff, normalize_idem, subN_trans, subN_refl
exists_at_of_mem_foldListproved—sizeOf_child_lt, foldList_cases
run_eq_meaningproved—at_append
funded_reachableproved—evaluatePrim_producer, getCont_le, step_debit, finalizerOr_debit, replace_sum, driveState_lift
adjointproved—Eliminator.lift_least, subN_trans, mapM_total, Eliminator.lift_upper
foldl_keepsproved——
mapM_cons_eq_someproved——
subN_fiberOf_iffproved——
subN_option_iffproved——
sizeOf_child_ltproved——
foldList_casesproved——
getCont_leproved——
step_debitproved—getCont_le
finalizerOr_debitproved—step_debit, getCont_le
Eliminator.lift_leastproved—UnionRule.lift_least
mapM_totalproved—mapM_cons_eq_some
UnionRule.lift_leastproved—subN_trans, mapM_source, joinAll_le
mapM_sourceproved—mapM_cons_eq_some
joinAll_leproved—joinAll_all
joinAll_allproved—foldl_all
foldl_allproved——