Last active
March 31, 2017 20:47
-
-
Save robertjlooby/db964957ece239a852322d249e2bc09b to your computer and use it in GitHub Desktop.
Three' Traversable instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem was with the order of
b
/b'
infoldr
. Thank you to Daniel Díaz for figuring it out.https://twitter.com/DiazCarrete/status/847908639952207872