The notion of  context  in functional languages no longer refers just to variables in scope. Context can capture additional properties of variables (usage patterns in linear logics; caching requirements in dataflow languages) as well as additional resources or properties of the execution environment (rebindable resources; platform version in a cross-platform application). The recently introduced notion of coeffects captures the latter, whole-context properties, but it failed to capture fine-grained per-variable properties.   We remedy this by developing a generalized coeffect system with annotations indexed by a coeffect  shape . By instantiating a concrete shape, our system captures previously studied  flat  (whole-context) coeffects, but also  structural  (per-variable) coeffects, making coeffect analyses more useful. We show that the structural system enjoys desirable syntactic properties and we give a categorical semantics using extended notions of  indexed comonad .   The examples presented in this paper are based on analysis of established language features (liveness, linear logics, dataflow, dynamic scoping) and we argue that such context-aware properties will also be useful for future development of languages for increasingly heterogeneous and distributed platforms.
['Tomas Petricek', 'Dominic A. Orchard', 'Alan Mycroft']
Coeffects: a calculus of context-dependent computation