The Environment as an Argument Context-Aware Functional Programming Pedro M. Martins ⋆ , Julie A. McCann, and Susan Eisenbach Imperial College London, {pm1108,jamm,susan}@doc.ic.ac.uk Abstract. Context-awareness as defined in the setting of Ubiquitous Computing [3] is all about expressing the dependency of a specific com- putation upon some implicit piece of information. The manipulation and expression of such dependencies may thus be neatly encapsulated in a language where computations are first-class values. Perhaps surprisingly however, context-aware programming has not been explored in a func- tional setting, where first-class computations and higher-order functions are commonplace. In this paper we present an embedded domain-specific language (EDSL) for constructing context-aware applications in the func- tional programming language Haskell. 1 Introduction With widespread availability of mobile computing devices such as mobile phones and tablets, practical implementations of context-aware applications have started to appear. However, we observe a divide between the solutions proposed by re- searchers and the practical solutions adopted by implementers. We believe that this is because the former solutions are too heavyweight and rigid, and force developers to sacrifice some freedom in designing their applications, for little practical gain. As a result, practical implementations are typically based on be- spoke implementations of context-aware behaviour. This prevents reusability of behaviour, but makes it easier for subtle bugs and programming errors to be re- peated throughout implementations of the same behaviour. It has been argued that this is an inevitable consequence of context-awareness. Indeed, Lieberman and Selker [8] present a simple model for context-awareness and postulates that due to the dynamic nature of context-aware applications, it is hard to specify a module’s behaviour in a way that will allow it to be reused at all. In this paper we show that through a deeper embedding of context-awareness semantics into a programming language, we are able to specify this behaviour and provide natural programming language constructs for it. In addition to this, by being aware of the semantics of context-awareness, the compiler for our language is able to verify statically whether a certain number of properties that we believe should be true for this type of behaviour actually hold. This allows us to reuse ⋆ Funded by FCT (Portugal) under grant SFRH/BD/61917/2009.