ListT.hs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {-# LANGUAGE TemplateHaskell #-}
  2. {-# LANGUAGE CPP #-}
  3. #if __GLASGOW_HASKELL__ > 800
  4. {-# OPTIONS_GHC -Wno-error=missing-signatures #-}
  5. #endif
  6. {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
  7. -- | Quickcheck properties for 'Agda.Utils.ListT'.
  8. module Internal.Utils.ListT ( tests ) where
  9. import Control.Applicative
  10. import Data.Functor.Identity
  11. import Text.Show.Functions
  12. import Agda.Utils.ListT
  13. import Internal.Helpers
  14. ------------------------------------------------------------------------------
  15. -- * Identity monad instance of ListT (simply lists)
  16. type List = ListT Identity
  17. foldList :: (a -> b -> b) -> b -> List a -> b
  18. foldList cons nil l = runIdentity $ foldListT c (Identity nil) l
  19. where c a = Identity . cons a . runIdentity
  20. fromList :: [a] -> List a
  21. fromList = foldr consListT nilListT
  22. toList :: List a -> [a]
  23. toList = foldList (:) []
  24. prop_concat xxs = toList (concatListT (fromList (map fromList xxs))) == concat xxs
  25. prop_idiom fs xs = toList (fromList fs <*> fromList xs) == (fs <*> xs)
  26. prop_concatMap f xs = toList (fromList . f =<< fromList xs) == (f =<< xs)
  27. ------------------------------------------------------------------------
  28. -- * All tests
  29. ------------------------------------------------------------------------
  30. -- Template Haskell hack to make the following $allProperties work
  31. -- under ghc-7.8.
  32. return [] -- KEEP!
  33. -- | All tests as collected by 'allProperties'.
  34. --
  35. -- Using 'allProperties' is convenient and superior to the manual
  36. -- enumeration of tests, since the name of the property is added
  37. -- automatically.
  38. tests :: TestTree
  39. tests = testProperties "Internal.Utils.ListT" $allProperties