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

Support Higher Kinded Types #408

Closed
sobolevn opened this issue Jun 7, 2020 · 6 comments
Closed

Support Higher Kinded Types #408

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

Comments

@sobolevn
Copy link
Member

sobolevn commented Jun 7, 2020

This feature is crutial before 1.0 release.

Currently, our interfaces are not universal. Many functions and methods do require to explicitly annotate all containers that they can work with. As a result users cannot create their own containers.

And we struggle to build useful abstractions (like MonadIO on top of IO and Future, see https://github.com/gcanti/fp-ts/blob/master/src/MonadIO.ts). Let's see this example: https://returns.readthedocs.io/en/latest/pages/context.html#requirescontextfutureresult-container

It can possibly work with both IO and Future containers. In the first case, it would be sync. But, in the second one it would be async. And the source code won't be changed at all! We would only need to substitute our monad stack.

def _fetch_post(
      post_id: int,
      client_get: Callable[[str], MonadIO[Response]],
  ) -> MonadIO[_Post]:
      return client_get(_URL.format(post_id)).bind_result(
          safe(tap(httpx.Response.raise_for_status)),
      ).map(
          lambda response: response.json(),
      )

Passing IOResult will run this code in sync, while FutureResult will run like real async code.

To make this happen, we need HKT!
I have spent a lot of time working on the initial implementation, but still no luck.

Related:

Native blockers:

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

That's exactly the same example I had in How Async Should Have Been: https://dev.to/gcanti/functional-design-tagless-final-332k

@sobolevn
Copy link
Member Author

Blocked by python/mypy#9001
Because I need a TypeQuery instance to find Kind[] types in the function signature.

@antonagestam
Copy link

Just lurking on this PR which seems really promising 🙌 Has there been any interest from mypy to internalize support for this further on?

@sobolevn
Copy link
Member Author

@antonagestam thanks! 👍

When this will be released, I will work with mypy team! I am pretty sure that we can incorporate some parts of our API into the standard API.

@sobolevn
Copy link
Member Author

BTW, your https://github.com/antonagestam/phantom-types project looks amazing!

@antonagestam
Copy link

@sobolevn Thanks! I'm finding it hard to find the time to get it off the ground but I'm currently making some changes to make it much more based around predicate functions which I think will make it a lot more useful and adaptable to different contexts :)

Exciting times in the world of typed Python!

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

2 participants