【24h】

On the Bright Side of Type Classes: Instance Arguments in Agda

机译:类型类的亮面:Agda中的实例参数

获取原文
获取原文并翻译 | 示例

摘要

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.
机译:我们提供实例参数:在依赖类型的纯函数式编程语言/校对助手Agda中,类型类和相关功能的替代方法。它们是函数参数的一种新的常规类型,可以通过类型定向的方式从调用站点范围中解析。该机制受Scala的隐式参数和Agda的现有隐式参数的启发,但两者在重要方面有所不同。我们的机制是为Agda设计和实现的,但是我们的设计选择也可以应用于其他编程语言。像Scala的隐式一样,我们没有为类型类及其实例提供单独的结构,而是依靠Agda的标准依赖类型记录,以便标准语言机制提供其他建议中缺少或昂贵的功能。像Scala一样,我们支持等效的本地实例。与Scala不同,采用我们新论点的函数是一等公民,可以通过标准方式进行抽象和操纵。与其他建议相比,我们避免了通过实例搜索机制引入单独的类型级计算模型的陷阱。范围内的所有值都自动成为实例解析的候选对象。我们方法的最后一个新颖之处在于,使用记录的现有Agda库无需进行任何修改即可获得类型类的好处。我们讨论了在Agda(将成为Agda 2.2.12的一部分)中的实现,并以monads为例,说明了它如何允许以与使用类型类的相应Haskell代码类似的方式使用Agda标准库中的现有概念。我们还将展示和讨论文献中某些与高级类型类相关的模式的等效项和替代方法,以及某些特定于我们系统的新模式。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号