I wrote an implementation for foldl and wanted to check if it worked, I tried some cases and it seems to be working well but I want to make sure.
I read about quickCheck and tried it, but I can't seem to make it work, this is the code
foldl'' :: (b -> a -> b) -> b -> [a] -> b
test :: Eq b => (b -> a -> b) -> b -> [a] -> Bool
test f e ls = foldl'' f e ls == foldl f e ls
when I run quickCheck test
it throws the following error:
No instance for (Show (b0 -> a0 -> b0))
arising from a use of `quickCheck'
Possible fix:
add an instance declaration for (Show (b0 -> a0 -> b0))
In the expression: quickCheck prueba
In an equation for `it': it = quickCheck prueba
Your property requires three inputs: a function, an element and a list. The problem is that QuickCheck does not know how to deal with functions in general.
One of the things QuickCheck needs to work, is the ability to write failing test cases to the console. For this, it needs values it can turn into a String
--anything in the Show
class. Since functions are not in Show
, it can't use them for inputs. That's where your error message comes from.
In general, using randomly generated functions for testing is going to be pretty tricky. I'd just write some concrete functions instead and let QuickCheck randomly generate the starting value and the list of elements.