This question is related to my other question about smallCheck
's Test.SmallCheck.Series
class. When I try to define an instance of the class Serial
in the following natural way (suggested to me by an answer by @tel to the above question), I get compiler errors:
data Person = SnowWhite | Dwarf Int
instance Serial Person where ...
It turns out that Serial
wants to have two arguments. This, in turn, necessitates a some compiler flags. The 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 where
series = generate (\d -> SnowWhite : take (d-1) (map Dwarf [1..7]))
My question is:
Was putting that
Identity
there the "right thing to do"? I was inspired by the type of theTest.Series.list
function (which I also found extremely bizarre when I first saw it):list :: Depth -> Series Identity a -> [a]
What is the right thing to do? Will I be OK if I just blindly put
Identity
in whenever I see it? Should I have put something likeSerial m Integer => Serial m Person
instead (that necessitates some more scary-looking compiler flags:FlexibleContexts
andUndecidableInstances
at least)?What is that first parameter (the
m
inSerial m n
) for?Thank you!