Inverse function in Scala

前端 未结 5 545
自闭症患者
自闭症患者 2021-01-02 23:01

Is there a way to express the inverse of any function in Scala?

For example if I have a function f like this:

(x: Int) => x + 1
         


        
5条回答
  •  -上瘾入骨i
    2021-01-02 23:28

    I am adding an answer because of another question marked as a duplicate of this one, and nobody seems to have mentioned this yet: it is theoretically possible to automatically compute the "inverse" (in the sense that it performs exhaustive search over the input, and answers "none" if there is no solution, within a finite amount of time) of functions over infinite sequences of binary digits: see the article "Seemingly impossible functional programs" (though it uses Haskell, not Scala).

    Practical utility of this exhaustive search is another matter, of course.

提交回复
热议问题