A Lazy Language Needs a Lazy Type System: Introducing Polymorphic Contexts

Most type systems that support polymorphic functions are based on a version of System-F. We argue that this limits useful programming paradigms for languages with lazy evaluation. We motivate an extension of System-F alleviating this limitation. First, using a sequence of examples, we show that for lazily evaluated languages current type systems may force one to write a program in an unnatural way; in particular, we argue that in such languages the relationship between polymorphic and existential types can be made more systematic by allowing to pass back (part of) an existential result of a function call as an argument to the function call that produced that value. After presenting our extension to System-F we show how we can implement the strict-state thread monad ST by using a returned existential type to instantiating a polymorphic function that returns that type. Currently this monad is built-in into the runtime system of GHC and as such has become part of the language. Our proposed language extension, i.e. the introduction of polymorphic contexts, reverses the relationship between the context of a function call and the called function with respect to where it is decided with which type to instantiate a type variable.

[1]  Robert Harper,et al.  Practical Foundations for Programming Languages , 2012 .

[2]  S. Doaitse Swierstra,et al.  Linear, bounded, functional pretty-printing , 2009, J. Funct. Program..

[3]  Emir Pasalic,et al.  Meta-programming With Built-in Type Equality , 2008, Electron. Notes Theor. Comput. Sci..

[4]  Didier Rémy,et al.  Modeling abstract types in modules with open existential types , 2009, POPL '09.

[5]  John C. Mitchell,et al.  Abstract types have existential type , 1988, TOPL.

[6]  Joost Engelfriet,et al.  Simple Multi-Visit Attribute Grammars , 1982, J. Comput. Syst. Sci..

[7]  Simon L. Peyton Jones,et al.  OutsideIn(X) Modular type inference with local assumptions , 2011, J. Funct. Program..

[8]  Richard S. Bird Using circular programs to eliminate multiple traversals of data , 2004, Acta Informatica.

[9]  Atze Dijkstra,et al.  Linearly Ordered Attribute Grammars: with Automatic Augmenting Dependency Selection , 2015, PEPM.

[10]  S. Doaitse Swierstra,et al.  Typing dynamic typing , 2002, ICFP '02.

[11]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[12]  Uwe Kastens,et al.  Ordered attributed grammars , 1980, Acta Informatica.

[13]  S. Doaitse Swierstra,et al.  Typed Transformations of Typed Grammars: The Left Corner Transform , 2010, Electron. Notes Theor. Comput. Sci..

[14]  Simon L. Peyton Jones,et al.  Lazy functional state threads , 1994, PLDI '94.

[15]  S. Doaitse Swierstra,et al.  Typed transformations of typed abstract syntax , 2009, TLDI '09.