Created
March 12, 2019 20:04
-
-
Save emanb29/cd1d2578135dfbc53014d545a7bbd38e to your computer and use it in GitHub Desktop.
Dotty Natural Numbers Proofs Using Dependent Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Main extends App { | |
| type Nat | |
| type Zero <: Nat | |
| type Succ[N <: Nat] <: Nat | |
| type One = Succ[Zero] | |
| type NonZero[X <: Nat] = X match { | |
| case Zero => Zero | |
| case Succ[_] => Succ[Zero] | |
| } | |
| type Add[X <: Nat, Y <: Nat] = X match { | |
| case Zero => Y | |
| case Succ[lessone] => Add[lessone, Succ[Y]] | |
| } | |
| type Two = Add[One, One] | |
| type Three = Add[Two, One] | |
| type Theer = Add[One, Two] | |
| type Twice[X <: Nat] = Add[X, X] | |
| println(implicitly[Three =:= Theer]) | |
| println(implicitly[Three =:= Succ[Twice[One]]]) | |
| // type Even[X] = X match { // TODO this seems impossible without existential types | |
| // case Twice[half] => X =:= Twice[half] | |
| // } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment