
18 May
2009
18 May
'09
4:57 p.m.
On Mon, May 18, 2009 at 11:33 AM, Eugene Kirpichov
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