Skip to content

Implement Maybe monad and custom mypy plugin #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Feb 4, 2019 · 8 comments
Closed

Implement Maybe monad and custom mypy plugin #25

sobolevn opened this issue Feb 4, 2019 · 8 comments

Comments

@sobolevn
Copy link
Member

sobolevn commented Feb 4, 2019

Currently it is impossible to use this monad due to this bug in typing:

x: Optional[int]
Monad.new(x)  # ?

Type will be: Some[Union[int, None]]
, not Union[Some[int], Nothing]
Related:

_ContainerType = TypeVar('_ContainerType', bound=Container)
_ValueType = TypeVar('_ValueType')
_NewValueType = TypeVar('_NewValueType')
class Maybe(GenericContainerOneSlot[_ValueType], metaclass=ABCMeta):
@overload
@classmethod
def new(cls, inner_value: Literal[None]) -> 'Nothing': # type: ignore
...
@overload # noqa: F811
@classmethod
def new(cls, inner_value: _ValueType) -> 'Some[_ValueType]':
...

@sobolevn
Copy link
Member Author

sobolevn commented Feb 4, 2019

Moreover it is possible to use Optional. And we do not rely on it internally.
And it can be replaced with Result.

@sobolevn
Copy link
Member Author

sobolevn commented Feb 4, 2019

We have to wait until python/typing#614 is resolved.
And then re-add this monad to the project with correct type.

@sobolevn sobolevn closed this as completed Feb 4, 2019
@sobolevn sobolevn changed the title Remove Maybe monad Reimplement Maybe monad Feb 4, 2019
@sobolevn
Copy link
Member Author

sobolevn commented Feb 4, 2019

Closed by accident.

@sobolevn sobolevn reopened this Feb 4, 2019
@sobolevn
Copy link
Member Author

We can probably try to write custom mypy plugin to solve:

  1. decorator @safe and @impure untyped parameters
  2. Maybe.new() type issue

Let's evaluate how hard it is to do.

@sobolevn sobolevn changed the title Reimplement Maybe monad Implement Maybe monad and custom mypy plugin Jun 13, 2019
@sobolevn
Copy link
Member Author

Refs #88

@sobolevn
Copy link
Member Author

It is also became clear to me that we should always return Maybe[A] from Maybe.new. So, there's no issue in typing.

@sobolevn
Copy link
Member Author

We can start working on Maybe monad!

@sobolevn
Copy link
Member Author

Closed with cf36f26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant