Skip to content

Instantly share code, notes, and snippets.

@robertjlooby
Last active March 31, 2017 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertjlooby/db964957ece239a852322d249e2bc09b to your computer and use it in GitHub Desktop.
Save robertjlooby/db964957ece239a852322d249e2bc09b to your computer and use it in GitHub Desktop.
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
Copy link
Author

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