Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Three' Traversable instance
traversable:
fmap: +++ OK, passed 500 tests.
foldMap: *** Failed! Falsifiable (after 6 tests):
<function>
Three' (1,4,[-4,3,-5,5]) 1 (-2)
RHS
RHS
RHS
LHS
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]))
@robertjlooby

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.

https://twitter.com/DiazCarrete/status/847908639952207872

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