Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)



The most important benefit is not that you CAN unwrap a value, but rather that you CANNOT NOT do it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: