Hacker News new | ask | show | jobs
by IsTom 4180 days ago
Is there return type polymorphism in Swift? Without it monad-generic operations are limited.
1 comments

Yes.

  func f()->Bool {
    return true
  }
  func f()->Int {
    return 5
  }

  let i:Int = f()
  let b:Bool = f()

  println(i) // Prints 5
  println(b) // Prints true
  
  // This would be compile error as ambiguous
  //println(f())