Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
modified (with something else)
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
All fixed. Marked as resolved.
This comment is hidden because it contains spoiler information about the solution
Good call, I missed that on the edit. Fixed now!
This comment is hidden because it contains spoiler information about the solution
That's what's known as a
RankNType
(or, in particular, a rank-2 type). Concrete information on it is a little difficult to come by, but you can read it straightforwardly: a value of the typeforall r h . Language => r h a
is one which is valid for all choices ofr
andh
such thatr
instantiatesLanguage
.What that ultimately means is two-fold:
We must construct our values using only the methods in the Language typeclass. These methods apply for all choices of
r
and thus do not fix us into using any particular choice of instantiating type. In other words,Term
s must be built using only the basis of functions from Language and nothing more.Term
s cannot rely on a particular choice ofh
. What this means is that the term itself must ultimately be some combination of calls to methods ofLanguage
such that the finalh
is unconstrained. We can see these constraints being lifted in calls tobefore
andlambda
, for instance. In terms of the language itself, this demands thatTerm
s are "closed", i.e. they do not refer to unbound variables.So, ultimately
Term
is a clever trick which allows us to ensure that values are built using only the methods inLanguage
and are closed.It's not in the spec. I don't test for what you should do in that case; I don't think you should worry too hard.