在纯函数语言中,是否有一个算法来获得逆函数? [英] In pure functional languages, is there an algorithm to get the inverse function?

查看:164
本文介绍了在纯函数语言中,是否有一个算法来获得逆函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像Haskell这样的纯函数语言中,有一个算法来获取函数的逆函数,当它是双射的时候(编辑)?

In pure functional languages like Haskell, is there an algorithm to get the inverse of a function, (edit) when it is bijective? And is there a specific way to program your function so it is?

推荐答案

在某些情况下,是的!有一篇美丽的文章,名为双向免费!其中讨论了一些情况 - 当你的函数有足够的多态性 - 在这里有可能,完全自动地导出一个反函数。 (它还讨论了当函数不是多态时,使问题变得困难。)

In some cases, yes! There's a beautiful paper called Bidirectionalization for Free! which discusses a few cases -- when your function is sufficiently polymorphic -- where it is possible, completely automatically to derive an inverse function. (It also discusses what makes the problem hard when the functions are not polymorphic.)

在函数可逆的情况下得到的是反函数输入);在其他情况下,你得到一个函数,试图合并旧的输入值和新的输出值。

What you get out in the case your function is invertible is the inverse (with a spurious input); in other cases, you get a function which tries to "merge" an old input value and a new output value.

这篇关于在纯函数语言中,是否有一个算法来获得逆函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆