Abstract
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.
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.
Original language | English |
---|---|
Title of host publication | Proceedings of the 28th Symposium on the Implementation and Application of Functional Programming Languages |
Place of Publication | New York, NY, USA |
Publisher | Association for Computing Machinery |
Number of pages | 12 |
ISBN (Print) | 978-1-4503-4767-9 |
DOIs | |
Publication status | Published - 2017 |
Publication series
Name | IFL |
---|---|
Publisher | ACM |
Volume | 2016 |
Keywords
- System-F
- existentials
- lazy evaluation
- state monad
- type systems