[swift-evolution] [Proposal] Higher Kinded Types (Monads, Functors, etc.)
al_skipp at fastmail.fm
Thu Dec 17 06:52:58 CST 2015
> On 17 Dec 2015, at 12:05, Andrey Tarantsov <andrey at tarantsov.com> wrote:
> So I don't want to hijack this thread with useless flame, so one last thought:
>> Int("9").map(f) // .Some(.Some(9))
>> Int("9").flatMap(f) // .Some(9)
>> Int("10").map(f) // .Some(.None)
>> Int("10").flatMap(f) // .None
> My bad. But doesn't it show just how unreadable it is? I guess you're used to it, but it looks like complete gibberish to me because I don't really know the vocabulary, and, more importantly, the kind of thinking that requires using a that vocabulary is actively against the kind of thinking I'm used to.
> Arguably it should just be the default behavior of map. Double-optionals are unruly.
It’s my understanding that these unruly double-Optionals are required in various parts of the Swift library. In particular with generators – a generator knows it’s got to the end when it encounters nil (.None). If it were only possible to have one level of Optional it would be impossible to enumerate an Array of Optionals. For example
Without the ability to represent .Some(nil), the generator would reach the end after ‘2’ in the Array and would never get to ‘4’, ‘5’.
> Now, I fully accept that everyone wants to write a different kind of Swift. I just don't want my code to be pestered with FP concepts, which will be unavoidable if too much FP makes it into the standard library. So please, don't forget to consider us the FP haters.
I wouldn’t want the FP concepts to be an immediate burden to users of Swift (for example having to be able to explain the monad laws before writing a ‘hello world’ program). However if these concepts are present I don’t see why it would be an immediate burden, life would go on happily as before and if people wish to delve into the FP aspects then they can do – they might find it quite fun, I do (and I most certainly don’t have a PHD in category theory : )
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution