Generic structure diff

Posted on 2016-07-24 by Oleg Grenrus

At the ZuriHac 2016 I worked on the new parsec-based parser for the *.cabal files. The obvious test case is to compare new and old parser results for all of Hackage. Traversing the Hackage is quite trivial. The difficult part is inspecting the result GenericPackageDescriptions to spot the difference. In the same event, Andres Löh presented his library generics-sop. Obvious choice to quickly put something together for the repetetive task. After all you can compare records field-wise. And if sum constructors are different, that's enough for our case as well! Generic programming ftw.

At the end, we get boilerplate-less diffing implementation for comparing nesting record types:

λ *SopDiff > prettyResultIO $ diff (Foo 1) (Bar $ Ex2 "bar" True)
- Foo
+ Bar
λ *SopDiff > prettyResultIO $ diff (Bar $ Ex2 "barr" False) (Bar $ Ex2 "bar" True)
Bar exName : 
- "barr"
+ "bar"
Bar exDone : 
- False
+ True

Gist source

Was written at ZRH airport, near the gate A75.

Site proudly generated by Hakyll