Questions tagged [structural-equality]

15 questions
15
votes
2 answers

Structural Equality in F#

I have a record type that includes a function: {foo : int; bar : int -> int} I want this type to have structural equality. Is there some way I can just mark that the bar should be ignored in equality tests? Or is there some other way around this?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
8
votes
2 answers

How make .NET Mutable Dictionary with StructuralComparison & Equality in F#

I Know F# have the MAP, but I wanna use the .NET Dictionary. This dict have key as string and values as F# values + the dict, ie: type ExprC = | StrC of string | BoolC of bool | IntC of int32 | DecC of decimal | ArrayC of int *…
mamcx
  • 15,916
  • 26
  • 101
  • 189
6
votes
1 answer

F# Record Structural Comparison Ordering

If I have an record such as: type MyDate = { Year : int Month : int Day : int } I know that F#'s structural comparison will ensure that when a list is sorted it will maintain a consistent order. My question is whether I can rely…
Tub
  • 1,563
  • 1
  • 10
  • 13
6
votes
4 answers

Implement IEquatable when T could be IEnumerable

I've read various questions similar to mine but none of them seem address my issue. I've a type like this: class MyObject : IEquatable> { // no generic constraints private readonly string otherProp; private readonly T value; …
jay
  • 1,510
  • 2
  • 11
  • 19
5
votes
1 answer

StructuralComparisons for arrays

In F#: [0] = [0] = true In C# or .NET BCL in general: StructuralComparisons.Equals(new int[] { 0 }, new int[] { 0 }) == false Why? Postscript: The reason I thought I had the "right" Equals was because this turned out to be true: var a = new { X =…
Bent Rasmussen
  • 5,538
  • 9
  • 44
  • 63
4
votes
1 answer

Is there any way to influence the code the F# compiler generates for structural equality?

Here is a specific example. I have a record type with floating point fields and I would like to be able to compare instances of this type for equality but of course the default compiler-generated implementation of structural equality and comparison…
dmg
  • 608
  • 8
  • 15
3
votes
2 answers

Why does Kotlin use == for structural equality and introduce === for referential equality

In general every design decision in Kotlin feels like it's both great in its own right and offers a nice transition from Java. As a Java developer you can start coding in it thinking of Kotlin as a more concise Java with less boilerplate, then…
G_H
  • 11,739
  • 3
  • 38
  • 82
2
votes
3 answers

Kotlin data class equality when one of the properties is a function

I wonder if a data class with one of the properties being a function, such as: data class Holder(val x: Data, val f: () -> Unit) can work at all, since the following test fails. val a = {} val b = {} Assert.assertEquals(a, b) Update: Use case for…
clearpath
  • 916
  • 8
  • 24
2
votes
1 answer

TypeScript generics: how to define type T which is structurally the same as other type S

I have a notion of a Step, which requires value of type A as an input and gives out a value of type B. class Step { constructor(private readonly f: (a: A) => B) { } public run(a: A): B { return this.f(a); } } Now I would like to…
2
votes
1 answer

How can I structurally deep-compare 2 lua tables which may contain cyclic references, where keys of a table may themselves be tables?

This question is similar to a previously posted question, How can I deep-compare 2 Lua tables, which may or may not have tables as keys? The thing is, the solution there works great for simple deep-compares. It doesn't handle cyclic references…
SoniEx2
  • 1,864
  • 3
  • 27
  • 40
2
votes
1 answer

How to express structural equality between trees in Alloy?

I have defined the following Alloy model that uses a single State object to point to the roots of two trees State.a and State.b. sig N { children: set N } fact { let p = ~children | ~p.p in iden and no iden & ^p } one sig State { a:…
Peter Slotko
  • 327
  • 2
  • 10
0
votes
1 answer

What defines structural equality?

In terms of structural equality, Why would (equal? (list 'a 'b)) evaluate to true but (equal? (list 2 'b) '(2 'b)) evaulates to false?
0
votes
2 answers

stable hashcode for IStructuralEquatable object

I need to build a stable (= does not vary with time) hashcode of an object. Specifically, I do not know the exact type of the object. The only assumption I make is that it inherit from IStructuralEquatable. So I need a method: static string…
nlips
  • 1,258
  • 9
  • 25
0
votes
1 answer

IEqualityComparer instance for two-dimensional arrays

F# supports structural equality of two-dimensional arrays with the = operator, and in F# collections such as Set. But how can I use the same equality comparison in the .NET class HashSet? By default it uses referential equality, and although there…
Todd Owen
  • 15,650
  • 7
  • 54
  • 52
-1
votes
2 answers

Are the derived classes of `System.Exception` structurall equivalent to `System.Exception`?

i am looking at user defined exceptions and system defined derived exceptions Is it correct that all (or in the most cases) the derived classes of System.Exception, whether user defined or system defined, are structurally equivalent to their…
Tim
  • 1
  • 141
  • 372
  • 590