• jasondj@ttrpg.network
    link
    fedilink
    arrow-up
    11
    ·
    1 year ago

    I’m sorry, I’m only a novice Python guy. Know enough to get two RESTful APIs to talk to each other and do some network automation or rudimentary Ansible plugins.

    What’s wrong with if isinstance(x, str):?

  • mikidep@lemmy.worldOP
    link
    fedilink
    arrow-up
    1
    ·
    9 months ago

    Op here back from the dead. This is in fact not a stab at dynamically typed languages, or at least not only: statically typed languages such as Java also support this kind of construct. In fact, one could develop a technically type safe programming language where an instanceof construct has sound semantics.

    What instanceof breaks is something called polymorphic parametricity, i.e. the fact that generic functions don’t know anything specific about the types they are generic over. This is the fundamental condition for what in the community is dubbed “theorems for free”, that is, naturality of generic functions between generic types.