|
|
|
|
|
by tylerhou
2605 days ago
|
|
> Go's error handling is essentially the same as Error/Either/StatusOr (returning errors as values). Not really, it's very annoying to chain calls which can error. Also, as another commenter mentioned, functions which can potentially fail should return sum types and not product types. Compare: do first <- computeFirst
second <- computeSecond
return $ f first second
and first, err := computeFirst()
if err != nil {
return nil, err
}
second, err := computeSecond()
if err != nil {
return nil, err
}
return f(first, second), nil
Even without do-notation the Haskell is considerably shorter: computeFirst >>= (\first ->
computeSecond >>= (\second ->
return $ f first second))
Agreed about exceptions, though; I dislike them as well. |
|
This is a great example, not to your point, but to the methodology of Go. You give a verbose Go example, that I expect the vast majority of readers here could understand, even if they've never written a single line of Go, followed by a terse but syntax-heavy Haskell example that I expect relatively few could.