[swift-evolution] [Proposal] Higher Kinded Types (Monads, Functors, etc.)

Al Skipp al_skipp at fastmail.fm
Wed Dec 16 06:39:22 CST 2015


> On 16 Dec 2015, at 11:11, Will Fancher via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello,
> 
> A potent problem in my experience with Swift has been the lack of a way to generalize code that is repetitive on the basis of higher kinded types. For the uninitiated, higher kinded types are the ability to reason about generic types with their type parameters as variable. 

For those thinking, “Hmm… What’s the benefit of all this crazy sounding stuff?”, there’s a rather good practical talk about Functors.

How I Learned to Stop Worrying and Love the Functor:
https://vimeo.com/132657092


Here’s an example that is used:

func sayHello(name: Optional<String>) -> Optional<String> {
  return name.map { "Hello \($0)" }
}

func sayHello(name: Array<String>) -> Array<String> {
  return name.map { "Hello \($0)" }
}

It doesn’t use the usual syntax sugar for Optionals and Array, to make it clear that the only difference between the 2 functions is the type signature. If were possible to express the concept of a Functor, we could write one function that would accept both Optionals and Arrays as parameters – and not just those 2, but any Functor (Result, Future, Signal…).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/a9901450/attachment.html>


More information about the swift-evolution mailing list