testing - Why does smallCheck's `Series` class have two types in the constructor? -
this question related other question smallcheck's test.smallcheck.series class. when try define instance of class serial in following natural way (suggested me answer @tel above question), compiler errors:
data person = snowwhite | dwarf int instance serial person ... it turns out serial wants have 2 arguments. this, in turn, necessitates compiler flags. following works:
{-# language flexibleinstances, multiparamtypeclasses #-} import test.smallcheck import test.smallcheck.series import control.monad.identity data person = snowwhite | dwarf int instance serial identity person series = generate (\d -> snowwhite : take (d-1) (map dwarf [1..7])) my question is:
was putting
identitythere "right thing do"? inspired type oftest.series.listfunction (which found extremely bizarre when first saw it):list :: depth -> series identity -> [a]what right thing do? ok if blindly put
identityin whenever see it? should have putserial m integer => serial m personinstead (that necessitates more scary-looking compiler flags:flexiblecontexts,undecidableinstances@ least)?what first parameter (the
minserial m n) for?thank you!
i'm user of smallcheck , not developer, think answer is
1) not really. should leave polymorphic, can without said extensions:
{-# language flexibleinstances, multiparamtypeclasses #-} import test.smallcheck import test.smallcheck.series import control.monad.identity data person = snowwhite | dwarf int deriving (show) instance (monad m) => serial m person series = generate (\d -> snowwhite : take (d-1) (map dwarf [1..7])) 2) series defined
newtype series m = series (readert depth (logict m) a) which means mis base monad logict used generate values in series. example, writing io in place of m allow io actions happen while generating series.
in smallcheck, m appears in testable instance declarations, such instance (serial m a, show a, testable m b) => testable m (a->b). has concrete effect pre-existing driver functions such smallcheck :: testable io => depth -> -> io () cannot used if have instances identity.
in practice, make use of fact writing custom driver function interleaves monadic effect logging of generated values (or such) inside said driver.
it might useful other things i'm not aware of.
Comments
Post a Comment