Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Three' Traversable instance
fmap: +++ OK, passed 500 tests.
foldMap: *** Failed! Falsifiable (after 6 tests):
Three' (1,4,[-4,3,-5,5]) 1 (-2)
module TraversableExercises where
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
data Three' a b =
Three' a b b
deriving (Eq, Ord, Show)
instance (Arbitrary a, Arbitrary b) => Arbitrary (Three' a b) where
arbitrary = do
a <- arbitrary
b <- arbitrary
b' <- arbitrary
return (Three' a b b')
instance (Eq a, Eq b) => EqProp (Three' a b) where
(=-=) = eq
instance Functor (Three' a) where
fmap f (Three' a b b') = Three' a (f b) (f b')
instance Foldable (Three' a) where
foldr f v (Three' _ b b') = f b' (f b v)
instance Traversable (Three' a) where
traverse f (Three' a b b') = Three' a <$> f b <*> f b'
main = do
quickBatch $ traversable (undefined :: Three' (Int, Int, [Int]) (Int, Int, [Int]))

This comment has been minimized.

Copy link
Owner Author

@robertjlooby robertjlooby commented Mar 31, 2017

The problem was with the order of b/b' in foldr. Thank you to Daniel Díaz‏ for figuring it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment