这个问题与我关于班级的其他问题有关。当我尝试以以下自然方式定义类的实例时(@tel 对上述问题的回答向我建议),我得到编译器错误:smallCheckTest.SmallCheck.SeriesSerial
data Person = SnowWhite | Dwarf Int
instance Serial Person where ...
事实证明,Serial想要有两个论点。反过来,这需要一些编译器标志。以下作品:
{-# 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]))
我的问题是:
把它放在
Identity那里是“正确的做法”吗?我受到Test.Series.list函数类型的启发(当我第一次看到它时我也觉得非常奇怪):list :: Depth -> Series Identity a -> [a]什么是正确的做法?
Identity每次看到就盲目的放进去会好吗?我应该放一些类似的东西Serial m Integer => Serial m Person(这需要一些看起来更可怕的编译器标志:FlexibleContexts至少UndecidableInstances)?第一个参数(
minSerial m n)是做什么用的?谢谢!