[Haskell-cafe] Finding the Convex Hull (Problem 12 of Real World Haskell)

Andrew Wagner wagner.andrew at gmail.com
Thu Mar 5 08:38:32 EST 2009


Whenever I'm looking for a bug in Haskell code, I find it helpful to start
by seeing if I can simplify the code any first. In this case, there are a
couple of things I notice:

   - validPointsOf is just a filter. It would be easier to write "valid ::
   MyDirection -> Bool" and then "validPointsOf = filter (valid . snd)"
   - Similarly, there's no need to write your own minimum-finder and call it
   lowestY. Instead, write (or derive!) an Ord instance, and then use the
   standard prelude function "minimum"
   - a small simplification of sortByCoTan: sortByCoTan pivot = sortBy
   (comparing (coTan pivot))

Hope this helps!

2009/3/5 Rob Crowther <weilawei at gmail.com>

> I wrote a "solution" to this problem, but it appears to return incorrect
> results. There's a pastebin of the code at
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2121 and a picture of the
> inputs, outputs, and expected results graphed at
> http://img510.imageshack.us/img510/9971/resultsg.jpg
>
> I'm wondering if this is a flaw in my code, my understanding of the
> problem, or both. Any ideas on how to track this one down would be very much
> appreciated.
>
> Thank you!
>
> --
> ヽ(^o^)ノ  -rob
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090305/3ae22521/attachment.htm


More information about the Haskell-Cafe mailing list