Circularity: philosophical types and real-world python

Already from a philosophical standpoint, the second-order or polymorphic λ-calculus presents circularity, but we can immediately note that

We are used to circularities in definitions of recursive functions and types, so we should not abandon hope about the system.

from chapter 9 of Type Theory & Functional Programming of Simon Thompson

In math topology we study cut points to define the connected spaces and homeomorphisms and that is the theoretical basis for the solution I’m proposing here in python

But what is the correct practical approach? They usually say you need modularity and many trendy buzzwords follow like microservices, but I present you a simpler, more effective way of programming.

Well, the 3 files, and are

A = 1

from circle1 import A
B = A + 1
from circle3 import C

from circle2 import B
C = B + 1
D = 'imported!'

Now, if you try importing circle3 you get a worrying circular import error. But which is the solution? Ask a philosopher or a mathematician. That is simply a disconnection due to a cut point, it is the philosophical fact that

lines are not homeomorphic to circles

From Wikipedia: Cut-point

Programmer’s solution: cut “and paste“: you simply need to import circle2 before circle3! Easy like that!

One thought on “Circularity: philosophical types and real-world python

  1. The philosophical part consists of my opinion on how to resolve the circular problem: you can prefer the modular approach for large projects and teams while you can leverage the order convention for small projects or teams.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s