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:
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.
[ Parent
| on HN ]
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
}
}