[Haskell-cafe] Haskell in 3 Slides

Ryan Ingram ryani.spam at gmail.com
Mon May 18 16:57:04 EDT 2009


On Mon, May 18, 2009 at 11:33 AM, Eugene Kirpichov <ekirpichov at gmail.com> 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


More information about the Haskell-Cafe mailing list