Functional type classes in Swift

As an exercise I tried to declare some protocols of functional type classes in Swift, but I already failed on Functor, because protocols in Swift can't be generic.

Instead of this the official recommendation is to use associatedtypes, which is often the right choice. But in this case it's not possible to declare the return type like that.

protocol Functor[A] {

    func map[B](f: (A) -> B) -> Functor[B]

}

No Comments Yet