我想Arbitrary为以下newtype 创建一个实例,以便将其用于QuickCheck:
newtype Wrapmaybe a = Wrapmaybe {getMaybe :: Maybe a} deriving (Eq, Show)
Run Code Online (Sandbox Code Playgroud)
我知道Arbitrary实例Maybe可以写成如下:
instance Arbitrary a => Arbitrary (Maybe a) where
arbitrary = frequency [(1, return Nothing), (1, liftM Just arbitrary)]
Run Code Online (Sandbox Code Playgroud)
如何Arbitrary在不出现类型错误或类型错误的情况下为以下内容编写实例:
instance Arbitrary a => Arbitrary (Wrapmaybe Maybe a) where
etc...
Run Code Online (Sandbox Code Playgroud)