Skip to content

Instantly share code, notes, and snippets.

@szeiger
Created January 11, 2012 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szeiger/1594475 to your computer and use it in GitHub Desktop.
Save szeiger/1594475 to your computer and use it in GitHub Desktop.
Compilation time affected hugely by type inference
sealed trait Nat {
type Self <: Nat
type + [_ <: Nat] <: Nat
type * [_ <: Nat] <: Nat
type Flip_^ [_ <: Nat] <: Nat
type ^ [T <: Nat] = T # Flip_^[Self]
type ++ = Succ[Self]
}
object Nat {
type _0 = Zero.type
type _1 = _0 # ++
type _2 = _1 # ++
type _3 = _2 # ++
type _4 = _3 # ++
type _5 = _4 # ++
type _6 = _5 # ++
type _7 = _6 # ++
type _8 = _7 # ++
type _9 = _8 # ++
type _10 = _9 # ++
println((null:( _2 # ^ [_4] )):( _1 # * [_10] # + [_6] ))
//println((null:( _2 # ^ [_5] )):( _3 # * [_10] # + [_2] ))
}
final object Zero extends Nat {
type Self = Zero.type
type + [X <: Nat] = X
type * [_ <: Nat] = Nat._0
type Flip_^ [_ <: Nat] = Nat._1
}
final class Succ[N <: Nat] extends Nat {
type Self = Succ[N]
type + [X <: Nat] = Succ[N # + [X]]
type * [X <: Nat] = (N # * [X]) # + [X]
type Flip_^ [X <: Nat] = (N # Flip_^ [X]) # * [X]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment