crclark / foundationdb-haskell

Haskell FFI bindings to the FoundationDB C API
https://crclark.github.io/foundationdb-haskell/
BSD 3-Clause "New" or "Revised" License
36 stars 5 forks source link

Feature request/discussion: An Eq instance for Database #47

Closed Dretch closed 2 years ago

Dretch commented 2 years ago

Hi!

It would convenient for me if Database had an Eq instance defined. I imagine this would behave similarly to Eq GHC.IO.Handle - i.e. a particular DatabasePtr would be equal only to itself, and then the Eq instance for Database would be the obvious one.

I suppose there may be some fundamental reason why this would not work, but I can't think of one.

If you consider this desirable, I will look into sending a PR.

crclark commented 2 years ago

This sounds perfectly reasonable to me, but it might not be too useful in practice, because the underlying FoundationDB C library only allows you to set up one database connection per process. Thus, I don't think it's even possible to ever have more than one Database in your program. So I'm curious why an Eq instance would be useful to you.

Regardless of that caveat, I'd certainly accept the PR. Pointer equality for Database equality sounds fine to me.

Dretch commented 2 years ago

it might not be too useful in practice, because the underlying FoundationDB C library only allows you to set up one database connection per process.

Ah, this is true -- I had not thought about that.

So I'm curious why an Eq instance would be useful to you.

I have a data type containing a Database and, since Eq is not defined for Database I had written an Eq MyDataType instance that ignores the Database field. I was thinking this was slightly hacky because the Database values could actually be different: however, as you point out, this is not possible.

With that said, I think it would still be convenient to have an Eq Database instance, since then one could use deriving (Eq) rather than writing custom Eq methods (or adding an orphan Eq Database instance). So I will look at sending a PR for this.