mathonsunday
12/6/2015 - 5:55 PM

reader.swift

First step is to desugar do notation. In this case we want to translate it to the bind (>>=) operator:

greeter =
    name >>= ask
    return ("hello, " ++ name ++ "!")
    
Now that it's desugared (not convinced I've done it correctly) I will translate it to Swift. 
I'm relying on the Reader monad implementation in Swiftz (https://github.com/typelift/Swiftz/blob/968075391aedb15ec51ff9d5b7d4921b8fa3a3c6/Swiftz/Reader.swift)
   
Current code is: 

func greeter(reader: Reader, name: String) {
  name >>= Reader.ask
  return ("hello, " ++ name ++ "!")
}