Control.ST pure type

本秂侑毒 提交于 2019-12-25 03:26:36

问题


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

I'm not sure what (out_fn result) out_fn means. Is it about constraining out_fn to be a function of result? Does it actually say anything about the input resource list?

The given explanation seems to be "...provided that the current list of resources is correct when producing that value" but I'm not sure how to interpret it.


回答1:


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

You see that the input resources don't depend on the result of a computation, but the output resources do. Now, let's say we have

MyResultType : Type
myResult : MyResultType

What's the type of pure myResult? It is STrans m MyResultType (f myResult) f. What are the input resources? f myResult, which could be anything. What are the output resources? Well, that depends on the result. But, this is pure, so the result is always myResult, and so the output resources are also f myResult. You see that the signature of pure is saying that the input and output resources can be anything, and that "anything" depends on f and myResult, but they have to be the same "anything"s no matter what.

I believe an equivalent way to see the type of pure is

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

Which is probably clearer. I don't know why this signature is not used.



来源:https://stackoverflow.com/questions/53570447/control-st-pure-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!