File: MonadFix.hs

package info (click to toggle)
haskell-quickcheck 2.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: haskell: 5,104; sh: 32; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 694 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# LANGUAGE TemplateHaskell, RecursiveDo #-}
import Test.QuickCheck
import Control.Monad.Fix

-- A simple (not complete) test for the MonadFix instance.
cyclicList :: Gen [Int]
cyclicList = do
  rec xs <- fmap (:ys) arbitrary
      ys <- fmap (:xs) arbitrary
  return xs

prop_cyclic :: Property
prop_cyclic =
  forAll (Blind <$> cyclicList) $ \(Blind xs) ->
    -- repeats with period 2
    and $ take 100 $ zipWith (==) xs (drop 2 xs)

prop_period2 :: Property
prop_period2 =
  expectFailure $
  forAll (Blind <$> cyclicList) $ \(Blind xs) ->
    -- does not always repeat with period 1
    and $ take 100 $ zipWith (==) xs (drop 1 xs)

return []
main = do True <- $quickCheckAll; return ()