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

Matthew Johnson matthew at anandabits.com
Wed Dec 16 23:22:14 CST 2015


> Looking beyond functional programming abstractions, higher-kinded types are a fancy way of saying "template template parameters”.

Thanks for bringing that up.  I almost mentioned it.  I didn’t because I know the Swift team wants to avoid a lot of what has been done with templates and am not sure exactly where you draw the line.  :)

> A textbook motivation for those from C++ land is Andrei Alexandrescu's "policy pattern", stuff like this:
> 
> protocol RefStoragePolicy: <*: class> {
>  typealias Ref: class
>  init(ref: Ref)
>  var ref: Ref
> }
> 
> struct Weak<T: class>: RefStoragePolicy { weak var ref: T }
> struct Unowned<T: class>: RefStoragePolicy { unowned var ref: T }
> struct Strong<T: class>: RefStoragePolicy { var ref: T }
> 
> class HeterogeneousRefConsumer<Storage: RefStoragePolicy> {
>  func consumeRef<T: class>(ref: T) {
>    let storage = Storage<T>(ref: ref)
>    doStuffWith(storage)
>  }
> }
> 
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list