【发布时间】:2018-02-08 18:12:11
【问题描述】:
我的印象是,a 类型的每个值都可以用 rank-2 多态类型 newtype Id a = Id {runId :: forall r. (a -> r) -> r } 以连续传递方式来描述。所以我派生了以下类型来相应地定义Reader:
newtype Reader e a = Reader {runReader :: forall r. ((e -> a) -> r) -> r}
然后我尝试构造一个这种类型的值并运行它:
reader f = Reader (\k -> k f) -- where is f's argument?
runReader (reader id) -- what is the 2nd argument?
如果Reader在CPS中的编码及其类型是有效的,我该如何使用呢?
【问题讨论】:
标签: haskell continuation-passing higher-rank-types scott-encoding