Assume I have a Haskell module named Foo
, defined in src/Foo.hs
. Assume also that Foo
exports a type Bar
.
Now I want to write unit tests for Bar
(for the whole Foo
module, actually), so I throw a couple of QuickCheck properties into test/FooTest.hs
; but hey, now I need to define an Arbitrary
instance for Bar
.
And there's the rub: in -Wall -Werror
mode, ghc
requires instance declarations to appear in one of two places: in the same file where the type is defined, or where the class is defined. But I don't want to clutter my Foo
module with a build dependency on QuickCheck, and I obviously cannot add an instance of Bar
to QuickCheck.
So how do I make my datatype an instance of Arbitrary
, for the purpose of unit testing only, without introducing a dependency on QuickCheck for users of my module and without tossing-Wall -Werror
out of the window?
Aucun commentaire:
Enregistrer un commentaire