Support Higher Kinded Types
See original GitHub issueThis 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:
- Lightweight higher-kinded polymorphism: https://www.cl.cam.ac.uk/~jdy22/papers/lightweight-higher-kinded-polymorphism.pdf
- Swift: https://bow-swift.io/docs/fp-concepts/higher-kinded-types/
- TypeScript: https://github.com/gcanti/fp-ts/blob/master/docs/guides/HKT.md
Native blockers:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:6 (4 by maintainers)
Top GitHub Comments
@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 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!