Code is coloured in many different ways. Coloured code have restrictions on how it can interact with code of a different colour.
For example, consider JavaScript async
code,
We say code is has two different colours async and synchronous.
Since async/await are promises and promises are monad, does this mean all monads colour code?
Yes!
Consider the Option monad. It remains coloured while passing around Some/None values, but can also become uncoloured.
Example of Option monad in Scala,
Similarly in Haskell IO is a monad that colours a program.
Since Haskell IO is isolating the side-effects of IO from pure functions, does this mean function purity colours code?
Yes!
Function purity has yet another set of colouring rules,
Notice how these are the same rules as synchronous/async function, yet it is a different colouring.
There are so many other forms of colouring,
requestAnimationFrame
s are colouredtype="module"
vs type="script"
are coloured. Modules import other modules declaratively, but scripts import other modules with dynamic import.evalulate
s are coloured since the calling Node.js JavaScript context is different the running Chrome Browser JavaScript context.Different colourings are mostly independent which makes code very confusing very fast. If one tries to optimize for one type of colouring, often it ruins the colouring of another. Everything becomes a huge tradeoff.
Can you skillfully navigate coloured code? We’re like to hear from you, Battlefy is hiring.