Skip to content

Support Higher Kinded Types #408

@sobolevn

Description

@sobolevn

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions