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:

  1. was putting identity there "right thing do"? inspired type of test.series.list function (which found extremely bizarre when first saw it):

    list :: depth -> series identity -> [a] 

    what right thing do? ok if blindly put identity in whenever see it? should have put serial m integer => serial m person instead (that necessitates more scary-looking compiler flags: flexiblecontexts , undecidableinstances @ least)?

  2. what first parameter (the m in serial 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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -