Skip to content

Instantly share code, notes, and snippets.

@non
non / ints.scala
Last active March 24, 2019 14:25
Type-level integers. Like shapeless' Nat, but supports negative numbers. Oh, and I've never actually run the code (but it compiles).
package quantity
// like Nat, but for integers
trait Z
// Pos means positive-or-zero, and Neg means negative-or-zero
trait Pos extends Z { type P <: Pos }
trait Neg extends Z { type N <: Neg }
class Zero extends Pos with Neg { type N = Zero }