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

Andrey Tarantsov andrey at tarantsov.com
Thu Dec 17 05:11:45 CST 2015

A tentative -1, based on the following two personal opinions:

First, I consider myself a smart person with a very broad experience with non-functional languages, but reading this makes my mind hurt, a lot:

>    typeclass Functor f where
>        fmap :: (a -> b) -> f a -> f b
> This makes it possible to build functions which operate not just on Maybe, but on any Functor.
>    fstrlen :: Functor f => f String -> f Int
>    fstrlen fstr = fmap length faster
>    protocol Functor {
>        typealias A
>        func fmap<FB where FB ~= Self>(f: A -> FB.A) -> FB
>    }

I understand what's going on here, but I never, ever want to see this code anywhere near (my) Swift.

Second, I consider this an anti-pattern:

> func sayHello(name: Optional<String>) -> Optional<String> {
> func sayHello(name: Array<String>) -> Array<String> {
> 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…).

Optional.map and Array.map do different things, and unifying them seems harmful.

I'm yet to see a compelling case where monads are useful either, for a real job (and not as a workaround for the idiosyncrasies of the type system).

I believe the way to convince the rest of us (and I would love to be convinced) is to provide a few real, “end-user” app-level use cases and explain the benefit in plain language. In particular, I don't understand the example by Jens Persson, although it seems like a valuable one.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/ccb3dc92/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open.gif
Type: image/gif
Size: 43 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/ccb3dc92/attachment.gif>

More information about the swift-evolution mailing list