My bad, I had a typo in toListOf
's type. K
is of course Const
. Here’s a running but failing test, trying to prove that toListOf . elements = id
on [Int]
. It fails with the first non-empty list [0]
:
module TinyLens where
import Data.Functor.Const ( Const(Const), getConst )
import Data.Semigroup ( Endo(Endo), appEndo )
import Test.QuickCheck ( quickCheck )
elements :: (Traversable t, Applicative f) => (a -> f b) -> (t a -> f (t b))
elements = traverse
toListOf :: ((a -> Const (Endo [a]) a) -> (s -> Const (Endo [a]) s)) -> (s -> [a])
toListOf t x = let foo = t $ Const . Endo . map . const
bar = getConst $ foo x
in appEndo bar []
propSameList :: [Int] -> Bool
propSameList xs = toListOf elements xs == xs
main = quickCheck propSameList
Any ideas? Maybe my choice of foo
is wrong?