The haskell book wants me to implement the traversable instance for
newtype Constant a b = Constant { getConstant :: a }
including all necessary superclasses. The code below passes Quickcheck/Checkers
, but acts funny
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
newtype Constant a b = Constant { getConstant :: a }
instance Functor (Constant a) where
fmap f (Constant a) = Constant a
instance Foldable (Constant a) where
foldr f z (Constant x) = z
instance Traversable (Constant a) where
traverse f (Constant a) = pure $ Constant a
type TI = []
main = do
let trigger = undefined :: TI (Int, Int, [Int])
quickBatch (traversable trigger)
When I try to use the traversable instance like so:
traverse (\x -> [x + 1]) $ Constant 5
I do not get Constant [5]
which I was hoping for, but rather
traverse (\x -> [x + 1]) $ Constant 5
:: (Num b, Num a) => [Constant a b]
What does it mean? Have I done something wrong?