Skip to content
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

Additional Direction Instances #22

Open
ischeinfeld opened this issue Feb 24, 2019 · 2 comments
Open

Additional Direction Instances #22

ischeinfeld opened this issue Feb 24, 2019 · 2 comments

Comments

@ischeinfeld
Copy link

ischeinfeld commented Feb 24, 2019

Would it make sense to derive Ord, Enum, and Bounded instances for Direction g? I am working on a game that should work in any grid and it seems to me that "turning left," for example, is well defined in all grids and could be defined in terms of Enum and Bounded. Or perhaps some other functionality could be added for iterating through directions, maybe with a different type class?

@mhwombat
Copy link
Owner

Thank you for the suggestion! Sounds like a good idea. I'll look into it.

@ischeinfeld
Copy link
Author

Nice! I've been working with a local copy where I simply derive them for each internal Direction type. But maybe a custom type class, i.e. Rotate, would make more sense semantically?

Also, I'm not sure if there is some way to make the Grid class enforce these (and other, such as Eq) constraints on the Index and Direction types? I've been writing code that works on arbitrary grids and my type signatures include constraints like

Grid g, Eq (Index g), Eq (Direction g), Enum (Direction g), Bounded (Direction g)

where it would be great to just write Grid g, since I don't see a case where, for example, indices and directions wouldn't be comparable or directions wouldn't be rotatable. I'm still learning Haskell though so maybe there is already a way around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants