Determining a total, terminating function

二次信任 提交于 2020-01-02 09:57:42

问题


I am trying to determine whether for the following type: ((a -> c) -> c) -> a a total, terminating function can be written using that type as a function signature? I understand that in order for a function to be total it has to be defined for all possible values of its input. However, I am not sure what exactly does it means for a function to be terminating. For a function to be terminating, does it have to return a value (and not go into an infinite loop for example)?

Further, what methods can I use to prove that a total, terminating function can be written using ((a -> c) -> c) -> a? Any insights are appreciated.


回答1:


For a function to be terminating, does it have to return a value (and not go into an infinite loop for example)?

Yes, that's what it means. Specifically, it means that you shouldn't cheat by giving a definition like

uncont :: ((a -> c) -> c) -> a
uncont f = uncont f

...or uncont = uncont, or uncont = undefined, all of which would mean you're generating a bottom value that can't actually be evaluated to a meaningful result.


Generally, to prove that a function of some type can be implemented... just implement it! ...If you can, that is, which ... (spoiler alert) you can't in this case! To prove that, you need to find a particular type-instantiation for which you could generate an impossible result by calling the function. Such results can usually be found by instantiating the result-type-variable with the Void type, and then demonstrating that you can still produce an argument for the function, which leads to a contradiction because the function (by assumption that it's total and terminates) would produce a value of type Void, which cannot be possible.



来源:https://stackoverflow.com/questions/57428251/determining-a-total-terminating-function

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