Type-level web APIs with Servant: an exercise in domain-specific generic programming

Type-level web APIs with Servant: an exercise in domain-specific generic programming
复制标题

使用 Servant 的类型级 Web API:特定领域通用编程的练习

DOI:
--
复制
发表时间:
2015
期刊:
WGP@ICFP
影响因子:
--
通讯作者:
Andres Löh
Andres Löh
中科院分区:
--
文献类型:
--
作者:
Alp Mestanogullari;Sönke Hahn;Julian K. Arni;Andres Löh

文献摘要

被引文献

相似文献

我们描述了Servant的设计和动机,Servant是一个用于描述Web API的可扩展的类型级DSL。Servant API是Haskell类型。API类型可以以几种不同的方式解释:作为处理请求的服务器,解释它们并将它们分派给适当的处理程序;作为可以正确查询API端点的客户端;作为API的系统文档;等等。Servant是完全可扩展的:API语言可以用新的构造来扩充,并且可以定义新的解释。使这一切成为可能的关键Haskell特性是数据类型,(开放)类型家族和(开放)类型类。我们使用的技术让人想起通用泛型编程。然而,大多数泛型编程库都对自动从许多不同领域中为一大类数据库派生程序感兴趣,我们只对DSL中用于描述API的一小类数据库感兴趣。
We describe the design and motivation for Servant, an extensible, type-level DSL for describing Web APIs. Servant APIs are Haskell types. An API type can be interpreted in several different ways: as a server that processes requests, interprets them and dispatches them to appropriate handlers; as a client that can correctly query the endpoints of the API; as systematic documentation for the API; and more. Servant is fully extensible: the API language can be augmented with new constructs, and new interpretations can be defined. The key Haskell features making all this possible are data kinds, (open) type families and (open) type classes. The techniques we use are reminiscent of general-purpose generic programming. However, where most generic programming libraries are interested in automatically deriving programs for a large class of datatypes from many different domains, we are only interested in a small class of datatypes that is used in the DSL for describing APIs.