Type-Safe Layer-Introduced Base Functions with Imperative Layer Activation

Layer-introduced base methods, which are the methods with new signatures in a layer and are added to a class, give layers more freedom to organize definitions of context-dependent behavior. However, we need to be careful so as not to call a layer-introduced base method while the layers that provide the method are inactive. Type-based solutions would help to avoid such a problematic situation, but existing ones are limited to context-oriented programming (COP) languages that have dynamically-scoped (i.e., the "with" based) layer activation. We propose a COP framework in Haskell that supports both imperative and dynamically-scoped layer activation mechanisms, as well as layer-introduced base functions. By representing a context as a stack of active layers in a type of a function in Haskell, type safety---including the guarantee of activation of a layer that provides a layer-introduced function---is checked by Haskell's type system. This paper shows how our framework encodes COP features in Haskell using a simple example.

[1]  Matteo Pradella,et al.  ContextErlang: introducing context-oriented programming in the actor model , 2012, AOSD '12.

[2]  Simon L. Peyton Jones,et al.  Giving Haskell a promotion , 2012, TLDI '12.

[3]  Robert Hirschfeld,et al.  An open implementation for context-oriented layer composition in ContextJS , 2011, Sci. Comput. Program..

[4]  Atsushi Igarashi,et al.  ContextFJ: a minimal core calculus for context-oriented programming , 2011, FOAL.

[5]  Kim Mens,et al.  Context-Oriented Programming with the Ambient Object System , 2008, J. Univers. Comput. Sci..

[6]  Simon Marlow,et al.  Parallel and Concurrent Programming in Haskell , 2013, CEFP.

[7]  Gian Luigi Ferrari,et al.  Typing Context-Dependent Behavioural Variation , 2012, PLACES.

[8]  Atsushi Igarashi,et al.  A Type System for Dynamic Layer Composition , 2012 .

[9]  Robert Hirschfeld,et al.  Language constructs for context-oriented programming: an overview of ContextL , 2005, DLS '05.

[10]  Andry Rakotonirainy,et al.  Context-oriented programming , 2003, MobiDe '03.

[11]  Hidehiko Masuhara,et al.  Context holders: realizing multiple layer activation mechanisms in a single context-oriented language , 2014, FOAL.

[12]  Kim Mens,et al.  Subjective-C - Bringing Context to Mobile Platform Programming , 2010, SLE.

[13]  Meng Wang,et al.  Aspect-oriented programming with type classes , 2007, FOAL.

[14]  Simon L. Peyton Jones,et al.  Composable memory transactions , 2005, CACM.

[15]  Oscar Nierstrasz,et al.  Context-oriented programming: beyond layers , 2007, ICDL '07.

[16]  Matteo Pradella,et al.  Context-oriented programming: A software engineering perspective , 2012, J. Syst. Softw..

[17]  Chung-chieh Shan,et al.  Lightweight monadic regions , 2008, Haskell '08.

[18]  Hidehiko Masuhara,et al.  Unifying Multiple Layer Activation Mechanisms Using One Event Sequence , 2014, COP'14.

[19]  Chris Okasaki,et al.  Simple and efficient purely functional queues and deques , 1995, Journal of Functional Programming.

[20]  Robert E. Strom,et al.  Typestate: A programming language concept for enhancing software reliability , 1986, IEEE Transactions on Software Engineering.

[21]  Éric Tanter,et al.  Foundations of Typestate-Oriented Programming , 2014, ACM Trans. Program. Lang. Syst..

[22]  Nicolas Tabareau,et al.  Effective Aspects: A Typed Monadic Embedding of Pointcuts and Advice , 2013, LNCS Trans. Aspect Oriented Softw. Dev..