/* * Copyright 2026 Flix Authors * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Trait for types that form a discrete sequence, and its functions.///pubmod Discrete {////// Trait for types that form a discrete sequence.////// Every value has an immediate successor and predecessor.////// The successor and predecessor functions must satisfy the following laws:////// - `prev(succ(x)) == x`/// - `succ(prev(x)) == x`/// - `succ(x) > x`, except at the maximum value of a bounded type (see below).////// For bounded types (e.g. `Int8`, `Int16`, `Int32`, `Int64`), `succ` wraps/// around from the maximum value to the minimum value, and `prev` wraps around/// from the minimum value to the maximum value. The unbounded `BigInt` never wraps.///pubtraitDiscrete[t] withOrder[t] {////// Returns the successor of the given `x`.///pubdefsucc(x: t): t////// Returns the predecessor of the given `x`.///pubdefprev(x: t): t }instanceDiscrete[Int8] {pubdefsucc(x: Int8): Int8 = x+1i8pubdefprev(x: Int8): Int8 = x-1i8 }instanceDiscrete[Int16] {pubdefsucc(x: Int16): Int16 = x+1i16pubdefprev(x: Int16): Int16 = x-1i16 }instanceDiscrete[Int32] {pubdefsucc(x: Int32): Int32 = x+1pubdefprev(x: Int32): Int32 = x-1 }instanceDiscrete[Int64] {pubdefsucc(x: Int64): Int64 = x+1i64pubdefprev(x: Int64): Int64 = x-1i64 }instanceDiscrete[BigInt] {pubdefsucc(x: BigInt): BigInt = x+1iipubdefprev(x: BigInt): BigInt = x-1ii }////// Returns `true` if `x` and `y` are adjacent, i.e. if one is the successor of the other.///pubdefadjacent(x: t, y: t): BoolwithDiscrete[t] =Discrete.succ(x) ==yorDiscrete.succ(y) ==x}