6

Represent a set by its characteristic function, for instance, the set of integers should be like

type Set = Int => Boolean  

And given some set and a transform function, the map function should be like

def map(s: Set, f: Int => Int): Set  

My original idea was

def map(s: Set, f: Int => Int): Set = (x: Int) => exists(s, (a: Int) => x == f(a))  

And I found it seemed hard to implement an unbounded version without iterating in some specific interval to determine whether there is certain "a".

Is it possible to implement an unbounded version in Scala? In other words, theroetically, regardless of the programming language, is it possible to get an unbound version?

Ziqi
  • 423
  • 3
  • 8
  • 2
    I guess it comes down to the question whether you can reverse `f`. Your iterative solutions does exactly that. In a general case knowing nothing about `f`? Probably not. – Victor Moroz Jul 03 '16 at 03:18
  • 1
    I have added a new answer to the old question http://stackoverflow.com/a/38176301/6428094 since nobody seems to have mentioned the (theoretical, not practical) solution. – FPstudent Jul 04 '16 at 02:52

0 Answers0