These QuickCheck properties don't really test your sort function. The `a' type variable will be instantiated to ().
So you will test with lists of units, like so: ghci> quickCheck (\xs -> isSorted (reverse xs)) OK, passed 100 tests. This can be simply solved by added a more specific type signature: isSorted :: [Int] -> Bool Surly, if the sort function works for Ints, it'll work for any Ord a. - Tom > ---------- Forwarded message ---------- > From: Ryan Ingram <[email protected]> > To: Eugene Kirpichov <[email protected]> > Date: Mon, 18 May 2009 13:57:04 -0700 > Subject: Re: [Haskell-cafe] Haskell in 3 Slides > On Mon, May 18, 2009 at 11:33 AM, Eugene Kirpichov <[email protected]> > wrote: >> The main bullet point is missing: Correctness. >> >> How could we have forgotten quickcheck? >> >>> quickCheck (\xs -> sort (sort xs) == sort xs) >> OK, 100 tests passed. > > I like this, but given that you have a whole slide, I might write this: > > isSorted :: Ord a => [a] -> Bool > isSorted [] = True > isSorted [x] = True > isSorted (x:y:rest) = x <= y && isSorted (y:rest) > >> quickCheck (\xs -> isSorted (sort xs)) > OK, 100 tests passed. > > Or, if you want to lead into a talk about fusion and/or higher order > functions: > > isSorted [] = True > isSorted (x:xs) = snd $ foldl' check (head x, True) xs where > check (prevElem, restSorted) thisElem = (thisElem, prevElem <= > thisElem && restSorted) > > -- ryan > _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
