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
期刊:
影响因子:
--
通讯作者:
Andres Löh
中科院分区:
文献类型:
--
作者:
Alp Mestanogullari;Sönke Hahn;Julian K. Arni;Andres Löh
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.