-
-
Notifications
You must be signed in to change notification settings - Fork 22
Create enum ranges #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
enum ranges
Outdated
| data Rank = R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | J | Q | K | A | ||
| deriving (Bounded, Enum, Eq, Ord) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We noticed this comes from your haskell-exercises repo, it's cool that you had an example handy to use :)
Instead of single-letter names for the contructors, maybe entire words would be more clear? It took us a minute to figure out what J, Q, K, A meant; I think seeing "jack", "queen", etc. could make it more immediately obvious that we're talking about playing cards.
data Rank = Rank2 | Rank3 | Rank4 | Rank5 | Rank6 | Rank7
| Rank8 | Rank9 | Rank10 | Jack | Queen | King | Ace
enum ranges
Outdated
| instance Show MyType where | ||
| show Foo = "Foo" | ||
| show Bar = "Bar" | ||
| show Baz = "Baz" | ||
|
|
||
|
|
||
| instance Enum MyType where | ||
| toEnum 0 = Foo | ||
| toEnum 1 = Bar | ||
| toEnum 2 = Baz | ||
|
|
||
| fromEnum Foo = 0 | ||
| fromEnum Bar = 1 | ||
| fromEnum Baz = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great for an in-depth explanation of how Enum works, but I think it's out of scope for the Phrasebook. The circumstances for manually writing Enum seem pretty rare (I don't think I've ever done it). Let's keep this page to derived instances only.
Renamed ranks and added more examples
|
I like this example a lot. This'll be released under the creative commons CC BY-NC 4.0 license - Please let us know if that's okay and how you'd like to be attributed (your name, and a link to a blog or social account if you'd like). |
|
I am very glad to be helpful :) Everything's okay, and I think a link to my GitHub and my username would be more than enough. |
No description provided.