property/orderable.fz
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion standard library feature orderable
#
# Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------
# orderable -- feature for immutable values that have an infix ≤ function
# predicate that defines a total order
#
# features inheriting from orderable define a total order of their values
#
# NYI: the compiler should check that features inheriting from this are
# actually immutable.
#
public orderable : partially_orderable
/* NYI: quantor intrinsics not supported yet:
inv
analysis: quantor.for_all2 T T fun(a, b T) => a <= b || b <= a,
*/
is
# equality implements the default equality relation for values of this type.
#
# This relation must be
#
# - reflexive (equality a a),
# - symmetric (equality a b = equality b a), and
# - transitive ((equality a b && equality b c) : equality a c).
#
# result is true iff 'a' is considered to represent the same abstract value
# as 'b'.
#
public redef type.equality(a,b property.orderable.this)
# NYI: BUG: see #4676
#
# String.fz:73:27: error 1: Incompatible types when passing argument in a call
# public fixed redef type.equality(a, b String) =>
#
# Actual type for argument #1 'a' does not match expected type.
# In call to : 'property.orderable.type.post equality'
# expected formal type: 'String.this.type (in type feature)'
# actual type found : 'String'
# assignable to : 'String'
# for value assigned : 'equality'
# To solve this, you could change the type of 'a' to a 'ref' type like 'String.this.type (in type feature) (boxed)'.
#
# post then
# result = (b <= a <= b)
=>
a <= b <= a
last changed: 2025-01-30