Skip to content
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

Typeclasses with several methods #83

Open
sobolevn opened this issue Jun 24, 2020 · 2 comments
Open

Typeclasses with several methods #83

sobolevn opened this issue Jun 24, 2020 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sobolevn
Copy link
Member

sobolevn commented Jun 24, 2020

There's a common use-case when we need to create a type-class with several methods. Like:

class Functor(Protocol[T]):
    def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
        ...

    @classmethod
    def from_value(cls, inner_value: V) -> Functor[V]:
        ...

Currently, there's no way we can do that.

I propose something like this:

@typeclass
class Functor(Protocol[T]):
    def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
        ...

    @classmethod
    def from_value(cls, inner_value: V) -> Functor[V]:
        ...

I am not sure how to bound it to the actual implementation.

@sobolevn sobolevn added enhancement New feature or request help wanted Extra attention is needed labels Jun 24, 2020
@sobolevn
Copy link
Member Author

sobolevn commented Jun 27, 2020

@Functor.instance
class Maybe(Generic[T]):
    def map(self, function: Callable[[T], Maybe[V]]) -> Maybe[V]:
        ...

    @classmethod
    def from_value(cls, inner_value: V) -> Maybe[V]:
        ...

@sobolevn
Copy link
Member Author

How is it different from a simple protocol?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

1 participant