This is referencing Philip Wadler’s 1989 paper “Theorems for Free”, which is fairly well known in the Haskell community: https://home.ttic.edu/~dreyer/course/papers/wadler.pdf
That looks like something I’ve seen somewhere and didn’t understand.
I need an explainer on this one
if (theorems_for(free)) make_instance_of(x, String)
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):
?This is referencing Philip Wadler’s 1989 paper “Theorems for Free”, which is fairly well known in the Haskell community: https://home.ttic.edu/~dreyer/course/papers/wadler.pdf
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.