High Order Function with Type Parameter

I modified the code to show that the encapsulated data type is open to extension by new traits.

Congrats for showing that by enforcing immutability+encapsulation then it is indeed possible to have a typeclass NatPos that is simultaneously Positive and a Natural. So I think you've entirely agreed with that assertion I've been repeating. :wink:

Your methodology of enforcing only the immutability on writing to a Natural and not to writing on a Positive enables another degree-of-freedom (to mutate positive values on an interface that can read natural values) which you gained with more granular typeclasses (which is orthogonal to the encapsulation with the module). But the cost of this is we can't enforce the safety with the compiler, because it is still possible to create semantics which fail at runtime (e.g. my original proof) due to implicit assumptions about immutability and intersection. I think it is naive to assume that such implicit assumptions won't become opaque to even the best programmers in more complex scenarios, but I will have to hope to find some example cases as I continue my analysis and study.

Note because Rust doesn't enforce this, as I showed upthread the proof that Rust (and Haskell) has unsafety. But perhaps every typing system will.

I don't yet know what I will conclude about whether typeclasses with modules of this form is the best we can do. I need more study and thought.

Btw it is nice to see that once we slowed down, we were actually talking past each other and our conceptualizations are congruent. I was worried that we were denying facts, when rather it was just an opaqueness about understanding that we had arrived to a congruent understanding. When you shifted to 4 interfaces (and encapsulation) from your prior arguments, then you had come into congruence with my assertion. And I didn't immediately realize it, until I studied your latest code example. I also learned some things along the way.