@@ -120,9 +120,8 @@ testPolymorphicFunctions _ = $(testProperties [
120
120
'prop_createT,
121
121
{- 'prop_replicateM, 'prop_generateM, 'prop_create, -}
122
122
123
- -- Unfolding (FIXME)
124
- {- 'prop_unfoldr, prop_unfoldrN, -}
125
- 'prop_unfoldr, 'prop_unfoldrM,
123
+ -- Unfolding
124
+ 'prop_unfoldr, 'prop_unfoldrN, 'prop_unfoldrM, 'prop_unfoldrNM,
126
125
'prop_constructN, 'prop_constructrN,
127
126
128
127
-- Enumeration? (FIXME?)
@@ -433,21 +432,27 @@ testPolymorphicFunctions _ = $(testProperties [
433
432
434
433
-- Because the vectors are strict, we need to be totally sure that the unfold eventually terminates. This
435
434
-- is achieved by injecting our own bit of state into the unfold - the maximum number of unfolds allowed.
436
- limitUnfolds f (theirs, ours) | ours >= 0
437
- , Just (out, theirs') <- f theirs = Just (out, (theirs', ours - 1 ))
438
- | otherwise = Nothing
435
+ limitUnfolds f (theirs, ours)
436
+ | ours > 0
437
+ , Just (out, theirs') <- f theirs = Just (out, (theirs', ours - 1 ))
438
+ | otherwise = Nothing
439
439
limitUnfoldsM f (theirs, ours)
440
- | ours >= 0 = do r <- f theirs
440
+ | ours > 0 = do r <- f theirs
441
441
return $ (\ (a,b) -> (a,(b,ours - 1 ))) `fmap` r
442
442
| otherwise = return Nothing
443
443
444
444
445
445
prop_unfoldr :: P (Int -> (Int -> Maybe (a ,Int )) -> Int -> v a )
446
446
= (\ n f a -> V. unfoldr (limitUnfolds f) (a, n))
447
447
`eq` (\ n f a -> unfoldr (limitUnfolds f) (a, n))
448
+ prop_unfoldrN :: P (Int -> (Int -> Maybe (a ,Int )) -> Int -> v a )
449
+ = V. unfoldrN `eq` (\ n f a -> unfoldr (limitUnfolds f) (a, n))
448
450
prop_unfoldrM :: P (Int -> (Int -> Writer [Int ] (Maybe (a ,Int ))) -> Int -> Writer [Int ] (v a ))
449
451
= (\ n f a -> V. unfoldrM (limitUnfoldsM f) (a,n))
450
452
`eq` (\ n f a -> Util. unfoldrM (limitUnfoldsM f) (a, n))
453
+ prop_unfoldrNM :: P (Int -> (Int -> Writer [Int ] (Maybe (a ,Int ))) -> Int -> Writer [Int ] (v a ))
454
+ = V. unfoldrNM `eq` (\ n f a -> Util. unfoldrM (limitUnfoldsM f) (a, n))
455
+
451
456
prop_constructN = \ f -> forAll (choose (0 ,20 )) $ \ n -> unP prop n f
452
457
where
453
458
prop :: P (Int -> (v a -> a ) -> v a ) = V. constructN `eq` constructN []
0 commit comments