How to make ad-hoc polymorphism less ad hoc
POPL '89 Proceedings of the 16th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
Implicit parameters: dynamic scoping with static types
Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
Type Classes with Functional Dependencies
ESOP '00 Proceedings of the 9th European Symposium on Programming Languages and Systems
Scripting the type inference process
ICFP '03 Proceedings of the eighth ACM SIGPLAN international conference on Functional programming
Type-checking multi-parameter type classes
Journal of Functional Programming
Faking it Simulating dependent types in Haskell
Journal of Functional Programming
Functional pearl: implicit configurations--or, type classes reflect the values of types
Haskell '04 Proceedings of the 2004 ACM SIGPLAN workshop on Haskell
Simple unification-based type inference for GADTs
Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming
RepLib: a library for derivable type classes
Proceedings of the 2006 ACM SIGPLAN workshop on Haskell
Proceedings of the 34th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
Practical type inference for arbitrary-rank types
Journal of Functional Programming
A history of Haskell: being lazy with class
Proceedings of the third ACM SIGPLAN conference on History of programming languages
Type checking with open type functions
Proceedings of the 13th ACM SIGPLAN international conference on Functional programming
TPHOLs '08 Proceedings of the 21st International Conference on Theorem Proving in Higher Order Logics
TPHOLs '08 Proceedings of the 21st International Conference on Theorem Proving in Higher Order Logics
Type classes as objects and implicits
Proceedings of the ACM international conference on Object oriented programming systems languages and applications
Haskell type constraints unleashed
FLOPS'10 Proceedings of the 10th international conference on Functional and Logic Programming
The implicit calculus: a new foundation for generic programming
Proceedings of the 33rd ACM SIGPLAN conference on Programming Language Design and Implementation
Generic conversions of abstract syntax representations
Proceedings of the 8th ACM SIGPLAN workshop on Generic programming
Hi-index | 0.00 |
We present instance arguments: an alternative to type classes and related features in the dependently typed, purely functional programming language/proof assistant Agda. They are a new, general type of function arguments, resolved from call-site scope in a type-directed way. The mechanism is inspired by both Scala's implicits and Agda's existing implicit arguments, but differs from both in important ways. Our mechanism is designed and implemented for Agda, but our design choices can be applied to other programming languages as well. Like Scala's implicits, we do not provide a separate structure for type classes and their instances, but instead rely on Agda's standard dependently typed records, so that standard language mechanisms provide features that are missing or expensive in other proposals. Like Scala, we support the equivalent of local instances. Unlike Scala, functions taking our new arguments are first-class citizens and can be abstracted over and manipulated in standard ways. Compared to other proposals, we avoid the pitfall of introducing a separate type-level computational model through the instance search mechanism. All values in scope are automatically candidates for instance resolution. A final novelty of our approach is that existing Agda libraries using records gain the benefits of type classes without any modification. We discuss our implementation in Agda (to be part of Agda 2.2.12) and we use monads as an example to show how it allows existing concepts in the Agda standard library to be used in a similar way as corresponding Haskell code using type classes. We also demonstrate and discuss equivalents and alternatives to some advanced type class-related patterns from the literature and some new patterns specific to our system.