Control.ST纯型

Control.ST pure type

pure : (result : ty) -> STrans m ty (out_fn result) out_fn 来自 http://docs.idris-lang.org/en/latest/st/state.html#strans-primitive-operations

我不确定 (out_fn result) out_fn 是什么意思。是关于将 out_fn 约束为 result 的函数吗?它真的说明了输入资源列表吗?

给定的解释似乎是 “...前提是当前资源列表在生成该值时是正确的”,但我不确定如何解释它。

STrans : (m : Type -> Type) ->
         (result : Type) ->
         (inRes : Resources) ->
         (outRes : result -> Resources) ->
         Type

您看到输入资源不依赖于计算结果,但输出资源依赖于计算结果。现在,假设我们有

MyResultType : Type
myResult : MyResultType

pure myResult 的类型是什么?是STrans m MyResultType (f myResult) f。输入资源是什么? f myResult,可以是任何东西。什么是输出资源?好吧,这取决于结果。但是,这是pure,所以结果总是myResult,所以输出资源也是f myResult。你看 pure 的签名是说输入和输出资源可以是任何东西,而 "anything" 取决于 fmyResult,但它们必须是无论如何都一样 "anything"。

我认为查看 pure 类型的等效方法是

pure' : (result : ty) -> STrans m ty resources (const resources)

这可能更清楚。不知道为什么不用这个签名