【问题标题】:How do spray's directives correspond to continuations?Spray 的指令如何与延续相对应?
【发布时间】:2017-03-03 01:06:45
【问题描述】:

我看不到 spray 的指令如何对应于 continuation passing style (CPS)

更具体地说,延续是 (a -> r) -> r(在 Haskell 中),但是当使用喷雾 directives(其类型为 Route->Route 其中type Route = RequestContext => Unit)时,我找不到这种类型((a -> r) -> r)在哪里.

Route->Routetype Route = RequestContext => Unit 都不像 (a -> r) -> r,那么指令与 CPS 有什么关系?

有人可以展示一下spray的指令correspond如何延续传递风格吗?

【问题讨论】:

    标签: scala spray continuations continuation-passing


    【解决方案1】:

    指令的最简单形式定义为

    abstract class Directive[L <: HList] {
      def happly(f: L => Route): Route
    }
    

    这正是(a -&gt; r) -&gt; r。你在 spray directives 文档中看到的是一个高级 DSL,它在底层构建了 Directive 实例。完整定义见Directive.scala

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 2011-08-24
      • 2018-08-04
      • 1970-01-01
      • 2019-09-30
      相关资源
      最近更新 更多