Ludwig.Equality

Module Members

referenceEquality

(Function)

Test for reference equality of two values. Reference equality is only guaranteed to work on values that are references, i.e. values of user-defined sum types.

Example:

type Resource:
    | Resource {name: String}

test01:
    let x: Resource {name: "My resource"}
    referenceEquality(x, x)  # => True

test02:
    let x: Resource {name: "My resource"}
    let y: Resource {name: "My resource"}
    referenceEquality(x, y)  # => False

test03:
    referenceEquality(1, 1)  # => False, integers are not references.

Type Signature

 fun (a, a) -> Bool
Argument: x

First reference.

Type: a

Argument: y

Second reference.

Type: a

Returns:

Whether or not the two references point to the same thing.

Type: Bool

structuralEquality

(Function)

Test for deep structural equality of two values.

Example:

x: structuralEquality(1, 1)                # => True
y: structuralEquality({foo: 1}, {foo: 1})  # => True
z: structuralEquality({foo: 1}, {foo: 2})  # => False

Comparing functions for equality will always result in False.

x: structuralEquality(fun x: x, fun x: x)  # => False

This implies that comparing data structures with embedded functions such as this one will also always result in false:

type Curve:
  name: String
  y:    fun(Int) -> Int

Another important thing to note is that comparing cyclical values for structural equality will not work, since that results in an infinite loop.

Type Signature

 fun (a, a) -> Bool
Argument: x

First value

Type: a

Argument: y

Second value

Type: a

Returns:

Whether or not the two values are structurally equal.

Type: Bool

structuralInequality

(Function)

Test if two values are not structurally equal. The opposite of structuralEquality.

Type Signature

 fun (a, a) -> Bool
Argument: x
Type: a
Argument: y
Type: a
Returns:
Type: Bool

logical NOT (!)=

(Operator)

operator != infixl 4:
  structuralInequality

Structural inequality test. See structuralInequality.


(Operator)

operator == infixl 4:
  structuralEquality

Structural equality test. See structuralEquality.