[Haskell-cafe] Haskell - string to list isusses, and more
Luke Palmer
lrpalmer at gmail.com
Mon Jun 15 05:11:35 EDT 2009
On Mon, Jun 15, 2009 at 3:03 AM, Luke Palmer <lrpalmer at gmail.com> wrote:
>
> The last thing: we made startsWithUpper less general in the process; it is
> undefined for empty strings. We need to verify that words never returns any
> empty strings. I did this using SmallCheck:
>
> ghci> import Test.SmallCheck
> ghci> smallCheck 10 $ \string -> all (not . null) (words string)
>
'Course, it turns out that SmallCheck never generates any spaces... ever.
Some verifier that is.
By careful inspection of the definition of words, I can see that it never
returns an empty string. I couldn't find a better way to convince myself of
this (I like to avoid looking at definitions when possible).
Luke
> Depth 0:
> Completed 1 test(s) without failure.
> Depth 1:
> Completed 2 test(s) without failure.
> Depth 2:
> Completed 5 test(s) without failure.
> Depth 3:
> Completed 16 test(s) without failure.
> Depth 4:
> Completed 65 test(s) without failure.
> Depth 5:
> Completed 326 test(s) without failure.
> Depth 6:
> Completed 1957 test(s) without failure.
> Depth 7:
> Completed 13700 test(s) without failure.
> Depth 8:
> Completed 109601 test(s) without failure.
> Depth 9:
> Completed 986410 test(s) without failure.
> Depth 10:
> Completed 9864101 test(s) without failure.
>
> So I am reasonably confident that words never gives me any empty strings.
>
> Tada! Your solution is almost exactly the same as the one-liners! :-)
>
> Luke
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090615/0e249480/attachment.html
More information about the Haskell-Cafe
mailing list