You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While rendering the diff error, I believe it will much more useful to also include the differing values in the error message. Going with the example used in the docs, I have something like the following in mind:
ghci> printDiffResult $ diff expr1 expr2
In field right:Both values use constructor Bin but fields don't match
In field right:Both values use constructor Atom but fields don't match
In field 0 (0-indexed):Not equal
Left value:1Right value:2
Of course this requires us to capture the two values as part of the TopLevelNotEqual constructor. I have actually hacked something together that works, but the main issue is that we now need the type in question to have Eq and Show instances. In my implementation I have added those constraints to the GADT declaration directly, but that required me to remove some Diff instances from the library, since not all the types we currently have Diff instances for have a Show instance by default (e.g. MVar, along with many others). It might be possible to workaround this by not adding those constraints to the GADT itself, but push them up to the rendering functions. Since I don't readily know much about generics-sop myself, I first wanted to ask if this is a good idea at all, or whether it was a deliberate choice to not go this route.
I would favour the approach you mentioned of keeping the constraints out of the GADT and having them in the rendering function instead. I'd recommend keeping printDiffResult as it is, and having a second function printDiffResultDetailed (or some better name) that includes the different values as you mentioned. Please feel free to open a PR and I'll take a look!
I started by adding the two a types to the TopLevelNotEqual constructor, and the rest of the changes resulted from trying to fix the emerging compilation errors. Since DiffError a now contains actual a values, this required addition of Eq a and Show a superclass constraints to corresponding deriving clauses. This in turn requires us to define constrained versions of eqNS and showsNS, and add All2 Eq xss and All2 Show xss to the corresponding instances that use these constrained functions. Playing this cat-and-mouse game of adding constraints and fixing resulting errors however, I finally got stuck trying to propagate the constraints involving the Code a type to the functions that require them. At this point, my lack of understanding of the overall design of generic-diff and relative inexperience with generics-sop overwhelmed me, and I gave up. I hope the WIP commit I pushed is still useful to you in figuring out what is it that went wrong with my attempt.
Activity
fpringle commentedon Feb 26, 2026
I would favour the approach you mentioned of keeping the constraints out of the GADT and having them in the rendering function instead. I'd recommend keeping
printDiffResultas it is, and having a second functionprintDiffResultDetailed(or some better name) that includes the different values as you mentioned. Please feel free to open a PR and I'll take a look!ozkutuk commentedon Apr 28, 2026
Here is my failed attempt at implementing this: ozkutuk/generic-diff@fpringle:generic-diff:main...wip-toplevel-values
I started by adding the two
atypes to theTopLevelNotEqualconstructor, and the rest of the changes resulted from trying to fix the emerging compilation errors. SinceDiffError anow contains actualavalues, this required addition ofEq aandShow asuperclass constraints to correspondingderivingclauses. This in turn requires us to define constrained versions ofeqNSandshowsNS, and addAll2 Eq xssandAll2 Show xssto the corresponding instances that use these constrained functions. Playing this cat-and-mouse game of adding constraints and fixing resulting errors however, I finally got stuck trying to propagate the constraints involving theCode atype to the functions that require them. At this point, my lack of understanding of the overall design ofgeneric-diffand relative inexperience withgenerics-sopoverwhelmed me, and I gave up. I hope the WIP commit I pushed is still useful to you in figuring out what is it that went wrong with my attempt.