[Haskell-cafe] Ensuring Type Class instances follow the 'rules'
ekirpichov at gmail.com
Fri May 29 02:13:11 EDT 2009
2009/5/29 Hemanth Kapila <saihemanth at gmail.com>:
> Hi all,
> Recently, I participated in a coding competition.
> As part of it, I had to write a program wherein I had to make my data-type
> an instance of Ord. An error in my implementation of compare resulted in me
> losing quite a bit of valuable time.
> As I wrote it, I had tested it out on the ghci and it seemed to work fine
> but I noticed that there was trouble when the List.sort started giving weird
> output. I then noticed that for certain instances (say t1,t2), both compare
> t1 t2 AND compare t2 t1 returned LT. Once I spotted it, it was easy enough
> to fix but I did lose an hour or so thinking something went wrong before I
> fed the list to the sort function.
> I was the only haskeller in the competition and I believe am among the first
> to finish a correct application (by a large margin, and) and I did manage to
> raise a bit of haskell-awareness, but if I had managed to spot the error
> earlier, the results would have been dazzling.
> Does any one here have any advice on dealing with such maladroitness on the
> part of the programmer, especially while creating instances to
> Thanks and regards,
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Web IR developer, market.yandex.ru
More information about the Haskell-Cafe