leibniz
leibniz copied to clipboard
Leibniz equivalence and Liskov substitutability library for Scala.
Leibniz Scala Library
The Leibniz’ equality law states that if a
and b
are identical then they
must have identical properties. Leibniz’ original definition reads as follows:
a ≡ b = ∀ f .f a ⇔ f b
and can be proven to be equivalent to:
a ≡ b = ∀ f .f a → f b
This library provides an encoding of Leibniz' equality and other related concepts in Scala. See my impromptu LC 2018 presentation for an overview.
Witnesses
-
Is[A, B]
(with a type alias toA === B
) witnesses that typesA
andB
are exactly the same. - Similarly,
IsK[A, B]
(with a type alias toA =~= B
) witnesses that typesA[_]
andB[_]
are exactly the same. Combinators exist that allow you to prove thatF[A] === F[B]
for anyF[_[_]]
or thatA[X] === B[X]
for anyX
. -
Leibniz[L, H, A, B]
witnesses that typesA
andB
are the same and that they both are in between typesL
andH
. -
Is[F, A, B]
witnesses type-equality for F-Bounded types. -
As[A, B]
witnesses thatA
is a subtype ofB
. -
As1[A, B]
witnesses thatA
is a subtype ofB
using existential types. -
Liskov[L, H, A, B]
is a bounded counterpart toAs[A, B]
. -
Constant[F]
witnesses that HKTF
is a constant type lambda. -
Injective[F]
witnesses that HKTF
is injective (not a constant type lambda :smiley:). -
Covariant[F]
witnesses that HKTF
is covariant (constant or strictly covariant). - Ditto other typeclasses / propositional types in
variance
package. - See my impromptu LC 2018 presentation for an overview.
Quick Start
resolvers += Resolver.bintrayRepo("alexknvl", "maven")
libraryDependencies += "com.alexknvl" %% "leibniz" % "0.10.0"
License
Code is provided under the MIT license available at https://opensource.org/licenses/MIT, as well as in the LICENSE file.