Some suggestions: While the custom Show and Read instances are probably nice for some testing on a local machine, they just clutter the code. They're not necessary. Furthermore, you shouldn't base your test cases on the user's Read instance. If you had used your own solution instead of the correct answers, my (evil) Read instance for Hand would have made it tremendously easy to cheat. You either have to make sure that the Read instance is still valid, or create Hand values without read.
That's not the only way to cheat. Since your tets cases don't include a random test, one can use a counter. You could prevent this by using hidden [ Module "System.IO.Unsafe", Module "Data.IORef"]. Or you simply write an additional property test. Keep in mind that the (randomly) generated hands should be valid.
Isn't there are some issues with writing an instance of Ord like this? Some hands will be tied according to Poker rules, and I guess EQ will be returned in those cases. However, this means that the Ord instance will not be a total order (indeed, not even a partial order). This means that you can't store hands realiably in a container relying on Ord, e.g. Data.Map or Data.Set.
Thank you, found another location for i -> l. The missing where is valid syntax when the instance definition itself is empty. These instances must be filled in before the test cases will compile.
No random tests. Fork with added random tests.
modified (with something else)
From the description: "This means that being r = result, r^n = x;"
is not really clear. Waybe reword to (root x n)^n = x?
Sorry, forgot to mention that if two hands are equal, first hand should be returned
betterHand function returns a Hand, so it is not clear what to do if hands are equal.
Well, in this kata you don't need to use maps or sets of hands. I used
Ord
instance to emphasize that one need to compare handsHowever, I changed kata so now it doesn't requires writing an
Ord Hand
Some suggestions: While the custom
Show
andRead
instances are probably nice for some testing on a local machine, they just clutter the code. They're not necessary. Furthermore, you shouldn't base your test cases on the user'sRead
instance. If you had used your own solution instead of the correct answers, my (evil)Read
instance forHand
would have made it tremendously easy to cheat. You either have to make sure that theRead
instance is still valid, or createHand
values withoutread
.That's not the only way to cheat. Since your tets cases don't include a random test, one can use a counter. You could prevent this by using
hidden [ Module "System.IO.Unsafe", Module "Data.IORef"]
. Or you simply write an additionalproperty
test. Keep in mind that the (randomly) generated hands should be valid.All fixed. Marked as resolved.
The description of the kata is all messed up.
Isn't there are some issues with writing an instance of Ord like this? Some hands will be tied according to Poker rules, and I guess EQ will be returned in those cases. However, this means that the Ord instance will not be a total order (indeed, not even a partial order). This means that you can't store hands realiably in a container relying on Ord, e.g. Data.Map or Data.Set.
I think when comparing two LengthLists, it should handle the case that one of them is infinite. (The infinite one is greater than the other one)
You're right. And thanks for fixing the
i
andl
.Thank you, found another location for
i -> l
. The missingwhere
is valid syntax when the instance definition itself is empty. These instances must be filled in before the test cases will compile.where
missing at bothinstance
declarationsi
should bel
instead (according to a post below that should have been fixed, but it still appears this way)It feels a bit clunky to have a fold function that takes seven functions. But you are of course correct.
Loading more items...