News for hackers. Stuff that matters.
Re:Functor and Monad in Swift by DanWaterworth on Friday January 02, 2015 @06:51AM (#8826438)
I'm not familiar with swift, but in Haskell, you can't write the following:

    flatMap :: Either e a -> (a -> Either e b) -> Either e b
    flatMap x f =
      case x of
        Left _ -> x
        Right x' -> f x'
In the case expression, you have to write `Left err -> Left err`, because `x` here has the type `Either e a`, but `Either e b` is expected.
Re:Functor and Monad in Swift by JSoto on Friday January 02, 2015 @03:45PM (#8828444)
Yeah, this is correct. This would be wrong:

    func map<U>(f: T -> U) -> Result<U> {
        switch self {
        case let .Value(value):
            return Result<U>.Value(Box(f(value.unbox)))
        case let .Error(error):
            // self is Result<T>, but the return type must be Result<U>
            return self
        }
    }