镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Structural type hierarchy ? #6

Open

Description

@asmodehn

Having a look at #3 it seems the main benefit compared to functools.singledispatch is the ability to work on structural types.

Therefore I wonder if one can define a hierarchy of protocols via python-typeclasses and have them checked with mypy as well ?

These days I find myself wanting to use haskell concepts in my python code (that I want to keep for the prototyping/iterative development feel) and I guess I actually want to replace nominal typing in my code with structural types + strict dynamic typing, but I am not quite sure how to go about it.

I've been wanting for a while to attempt to implement typeclasses (metaclasses were my initial take), so I'm happy to find this, thanks.

Activity

  1. changed the title [-]Structural type hierarchy[/-] [+]Structural type hierarchy ?[/+] on Jan 18, 2020
  2. thejohnfreeman commented on Jan 18, 2020

    @thejohnfreeman
    Owner

    You mean a hierarchy of typeclasses, e.g. the way Monad refines Applicative refines Functor in Haskell? If not that, maybe an example can help me understand what you're looking for.

  3. asmodehn commented on Jan 19, 2020

    @asmodehn
    Author

    Yes exactly that.
    I've been wanting to do that in Python for a while to define explicit interfaces/way to use my class instances, without having traditional class inheritance getting in the way.
    I've been looking for a kind of "de-facto standard" package for it without luck so far.

    I believe it's called a trait in other imperative/object languages, but I haven't tried any 'traits' implementation in python just yet to know if it's actually the same or not... I know only of https://github.com/enthought/traits and https://github.com/ipython/traitlets

    Thanks for any hints on that topic !

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions