3 ms·
The Python example feels like a strawman. You can write Python in a way that gets you most of the benefits of the Haskell version if you wanted to: @datacl
by drdrey 2y ago
The Python example feels like a strawman. You can write Python in a way that gets you most of the benefits of the Haskell version if you wanted to:
@dataclass
class InvalidResultError:
result: str
def do_something() -> int | InvalidResultError:
result = get_result()
return 42 if result == "a result" else InvalidResultError(result)
Using a dataclass like this seems a little overkill, but it does get you something close to `Either`.
I also don't understand the argument against nullable types: you could return `int | None` here, which would be the same as treating a `Maybe` (you have to explicitly consider the case where there is no value)
- deleted 2y ago[deleted]
- rbonvall 2y agoThe most important benefit is not that you CAN unwrap a value, but rather that you CANNOT NOT do it.