Thanks for the proposed addition. I am not sure if this use case is frequent enough to warrant it being on the tool.
When it is needed, gathering errors can be replicated without changing the tool itself with the following short "plug-in" module:
module Errorable where
import Test.LeanCheck
data MaybeError = Ok | Error String deriving Show
class Errorable a where
tierrors :: a -> [[([String], MaybeError)]]
instance Errorable MaybeError where
tierrors merr = [[([],merr)]]
instance (Errorable b, Show a, Listable a) => Errorable (a->b) where
tierrors perr = concatMapT tierrorsFor tiers
where
tierrorsFor x = mapFst (showsPrec 11 x "":) `mapT` tierrors (perr x)
mapFst f (x,y) = (f x, y)
resultsWithErrors :: Errorable a => a -> [([String], MaybeError)]
resultsWithErrors = concat . tierrors
... then used with the following code:
import Errorable
error_prop_not_3 :: Int -> MaybeError
error_prop_not_3 3 = Error "it's three!"
error_prop_not_3 _ = Ok
main :: IO ()
main = putStrLn $ unlines $ map show $ take 10 $ resultsWithErrors error_prop_not_3
Thanks for the proposed addition. I am not sure if this use case is frequent enough to warrant it being on the tool.
When it is needed, gathering errors can be replicated without changing the tool itself with the following short "plug-in" module:
... then used with the following code:
to arrive at:
Whenever one needs a custom
Testable
instance, declaring a separateSomethingable
instance is a very flexible and relatively easy solution.