So I have been reading, how you can convert ADTs into what resembles Real numbers and manipulating them, on pages like this SO question and this 3 part series and especially this.
The "Trouble" section of the last link caught my eyes and I tried to solve for Nat
in it even though the article states it's impossible.
Nat = 1 + Nat
Nat - Nat = 1
Nat(1 - 1) = 1
Nat = 1 / (1 - 1)
This might seem like total nonsense since I just divided by 0 (and you might be right), but if you read any of those links or something similar, then you'll notice that it looks very similar to a definition of a list.
List(x) = 1 / (1 - x)
So you could write Nat like Nat = List(1) = 1 + 1 + 1 + ...
, which is exactly what you would get by repeated substitution in the starting equation. This is also equivalent to defining Natural numbers like this in Haskell:
type Nat = [()]
Which is definitely a valid encoding of Natural numbers, where 0 = []
and S(N) = () : N
.
So my question is how come did I get a valid result out of this? I just divided by zero. Not to mention the starting equation itself is pretty much a contradiction.
So how come I got something that makes sense at the end of this? Is this just pure coincidence or is the division by 0 somehow defined in this context that makes sense?