public open import Arith::Nat
public open import Arith::Bool
open import Paths
open import Algebra::Formula

open data Int
| signed Bool Nat
| posneg : neg 0 = pos 0

def possigned true
def negsigned false

def negate Int : Int
| signed b nsigned (not b) n
| posneg iposneg (~ i)

def succInt Int : Int
| signed true npos (suc n)
| signed false (suc n) ⇒ neg n
| signed false zeropos 1
| posneg ipos 1

def abs Int : Nat
| signed _ nn
| posneg i ⇒ 0

// TODO: reimplement using univalence
def predInt (x : Int) : Intnegate (succInt (negate x))

def subI (x y : Int) : IntaddI x (negate y)

def addI : BinOp Int
| signed _ 0, nn
| posneg _, nn
| signed true (suc m), nsuccInt (addI (pos m) n)
| signed false (suc m), npredInt (addI (neg m) n)

/*
def addI-comm (a b : Int) : addI a b = addI b a
| pos n, pos m => pmap pos (+-comm n m)
| neg n, neg m => pmap neg (+-comm n m)
| pos n, neg m => idp
| neg n, pos m => idp
*/