mirror of
https://github.com/barrucadu/dejafu.git
synced 2024-12-19 03:21:49 +03:00
8944ea97a5
This allows results to be naturally reported as lazy trees, rather than as lists representing a tree traversal. This in turn means that the actual bound can be moved outwards to the testing code, and not used at all in the runner. Trees let us do nice things with shrinking and short-circuiting, if we make the (fairly reasonable) assumption that the children of a buggy result will exhibit the same bug. Storing results as trees does complicate the predicate helper functions somewhat, but I think the clarity gained in the actual SCT code is well worth it.
32 lines
851 B
Haskell
Executable File
32 lines
851 B
Haskell
Executable File
-- | Extra list functions and list-like types.
|
|
module Data.List.Extra where
|
|
|
|
import Control.DeepSeq (NFData(..))
|
|
|
|
-- * Regular lists
|
|
|
|
-- | Check if a list has more than some number of elements.
|
|
moreThan :: [a] -> Int -> Bool
|
|
moreThan [] n = n < 0
|
|
moreThan _ 0 = True
|
|
moreThan (_:xs) n = moreThan xs (n-1)
|
|
|
|
-- * Non-empty lists
|
|
|
|
-- This gets exposed to users of the library, so it has a bunch of
|
|
-- classes which aren't actually used in the rest of the code to make
|
|
-- it more friendly to further use.
|
|
|
|
-- | The type of non-empty lists.
|
|
data NonEmpty a = a :| [a] deriving (Eq, Ord, Read, Show)
|
|
|
|
instance Functor NonEmpty where
|
|
fmap f (a :| as) = f a :| map f as
|
|
|
|
instance NFData a => NFData (NonEmpty a) where
|
|
rnf (x:|xs) = rnf (x, xs)
|
|
|
|
-- | Convert a 'NonEmpty' to a regular non-empty list.
|
|
toList :: NonEmpty a -> [a]
|
|
toList (a :| as) = a : as
|