The document presents a coeffect type system that generalizes effect systems. Coeffect systems track context-dependent computations using comonads rather than monads. The coeffect calculus models both per-variable and whole-context dependencies using indexed comonads. It can capture properties like variable liveness, implicit parameters, and distributed computing contexts.
AWS Community Day CPH - Three problems of Terraform
Coeffects: A Calculus of Context-Dependent Computation
1. Coeffects:A calculus of context-dependent computation
Tomas Petricek, Dominic Orchard and Alan Mycroft
University of Cambridge
{name.surname}@cl.cam.ac.uk|@tomaspetricek| @dorchard
3. Properties of computations
Effect systems
Effects on environment
Modeled using monads
Coeffect systems
Requirements on environment
Modeled using comonads
Γ⊢푒:휏&흈
Γ@풓⊢푒:휏
4. View from the extreme left
Variable related
Liveness
Bounded linear logic
Data-flow programming
Provenance
Environment related
Implicit parameters
Type classes
Distributed computing
Platform versioning
6. Coeffect calculus for bounded reuse
Coeffect annotations
track number of variable uses
vectorof variable annotations + function annotation
richer structure than effect systems
푦:int@1⊢휆푥→푦+푥+푥∶푖푛푡→ퟐ 푖푛푡
10. Coeffect calculus for implicit parameters
Tracking implicit parameters
Non-determinism can be fixed by annotation
@{?zone}⊢휆()→?time+?zone∶푢푛푖푡 {?zone} 푡푖푚푒
time} @{?time,?zone}⊢휆()→?time+?zone∶푢푛푖푡→∅ 푡푖푚푒
11. Coeffect calculus for implicit parameters
Tracking implicit parameters
Annotation does not mirror context structure
Not the same as reader monadΓ,푥:휏1@푟∪푠⊢푒:휏2Γ@푟⊢휆푥.푒∶휏1→푠 휏2
13. Unified system
Coeffect scalar structure (⊗,⊕,use,ign,≤)
Generalized semiringstructure
Individual variable or function annotations
Shape-indexed coeffect(⨲,,⊥)
Context splittingand merging
Per-variable or whole-context
⨲
14. Semantics using indexed comonads
Monadic semanticsComonadic semantics
It is not as simple
휆-calculus is asymmetric (many to one)
per-variable orwhole-context? Γ@푹⊢푒:휏:푪푹Γ→휏Γ⊢푒:휏&흈:Γ→푴흈휏
15. Why coeffects matter?
generalize interesting systems
liveness, data-flow, implicit parameters, type classes
comonadsare cool
model both per-variable and whole-context
indexed
{tomas.petricek, dominic.orchard, alan.mycroft}@cl.cam.ac.uk @tomaspetricek|@dorchard| #coeffects