dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
908 stars 211 forks source link

Can `ExtractError` have an `Eq` instance? #2481

Closed NicolasT closed 1 year ago

NicolasT commented 1 year ago

Currently, the InvalidDecoder type doesn't have an Eq instance. Hence, the result of extract auto expr, which has type Extractor Src Void a == Validation (ExtractErrors Src Void) == Validation (DhallErrors (ExtractError Src Void)), doesn't have an Eq instance (even though Validation has one for (Eq e, Eq a) => Eq (Validation e a) and DhallErrors for Eq e => Eq (DhallErrors e)).

ExtractError is defined as

data ExtractError s a =
    TypeMismatch (InvalidDecoder s a)
  | ExpectedTypeError ExpectedTypeError
  | ExtractError Text

where ExpectedTypeError and Text have their proper Eq instance, but InvalidDecoder s a doesn't. This seems to be a pair of Expr s as which has an Eq instance: (Eq s, Eq a) => Eq (Expr s a).

In my case, s is Src and a is Void, which both have Eq instances.

Hence, is there a reason not to derive an Eq for InvalidDecoder s a (and then for ExtractError as well)?

The reason I'm asking: I'm using Hedgehog's tripping property test to ensure ToDhall and FromDhall instances obey (basically) \v -> let e = embed inject v in pure e == extract auto e. Given how tripping is defined (tripping :: (MonadTest m, Applicative f, Show b, Show (f a), Eq (f a), HasCallStack) => a -> (a -> b) -> (b -> f a) -> m ()), I need to throw out the errors (since there's no Eq instance for f a) by taking the result of extract auto b, turning it into Maybe a, discarding any potential errors (which would otherwise end up in Hedgehog's error message).

Gabriella439 commented 1 year ago

There's no particular reason why it's missing an Eq instance. I'd accept a PR to add it