
There's a mathematician in your compiler - alokrai
https://humanreadablemag.com/issues/2/articles/theres-a-mathematician-in-your-compiler
======
04091948
> If we can start from an assumption and perform a series of logical
> deductions and reach True, then we know our original assumption is True,
> that it is provable

is this a difference between mathematical and natural language?

my understanding is if you deduce something true from an assumption it means
nothing.

you need to deduce something false and thus the negation of your assumption is
true.

~~~
bregma
> my understanding is if you deduce something true from an assumption it means
> nothing.

Your understanding is not complete.

If you start from a set of assumptions and perform a series of logical
deductions to reach a conclusion, you have proven that given the assumptions
are true, the conclusion is true. You have a proof of correctness under the
assumptions.

If you can go on to demonstrate your conclusion is false (say, with a single
counterexample) then it will prove that at least one of your original
assumptions is false. You now have some provably reliable knowledge .

~~~
thaumasiotes
>> my understanding is if you deduce _something true_ from an assumption it
means nothing.

> Your understanding is not complete.

> If you start from a set of assumptions and perform a series of logical
> deductions to reach a conclusion, you have proven that given the assumptions
> are true, the conclusion is true. You have a proof of correctness under the
> assumptions.

04091948 is completely correct here.

If you assume P and prove Q, then you've proven that P implies Q.

If you assume P and prove True, then you've proven that P implies True. This
is the same thing as proving nothing, since everything implies True.

------
ivanbakel
Super impressed that you can develop type inequality in Scala. Haskell, the
logical darling, can't do it in the general case.

~~~
tiborsaas
Can you ELI5 type inequality?

~~~
ivanbakel
Haskell lets you express that types unify: `a ~ b` says that `a` unifies with
`b`, and similarly `Int ~ b` or `Bool ~ Char` (though the last one is clearly
false).

But there's no equivalent for non-unification - `a /~ b`. You can _sort of_
hack it by asking the compiler "do these types unify _right now_ ", and then
negating the response you get, but that doesn't work for types which
_eventually_ unify, but just fail to at the moment.

A good example is with non-injective type functions. To show `Maybe a ~ Maybe
b`, you can exploit the fact that `Maybe` is an injective type constructor to
simplify the problem to deciding if `a ~ b`. But if you have an ad-hoc type
function which is _not_ injective, say `Foo`, then it's possible that `Foo a ~
Foo b` even if `a /~ b`. It's worse if you have two different type functions -
`Foo a ~ Bar b`. Those types fail to unify immediately because `Foo` is
definitely different to `Bar` - but depending on the final values of `a` and
`b`, the types they result in may unify.

~~~
philzook
You can achieve a certain amount of type disequality in Haskell. It isn't
necessarily easy or sufficient for all purposes. There is a type family that
returns a type level Bool for equality here.
[https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-...](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-
Type-Equality.html)

There are some older techniques here
[http://okmij.org/ftp/Haskell/typeEQ.html](http://okmij.org/ftp/Haskell/typeEQ.html)

------
m23khan
this is a very interesting read.

