-
Notifications
You must be signed in to change notification settings - Fork 53
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
split scenario construction into separate sublibrary #1719
Conversation
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.
All the other sublibraries so far made sense to me, but I confess being confused about this one.
- It is named
swarm-world
, but the title of this PR says "scenario construction" - There is some stuff in here that seems like it should belong in
swarm-engine
, the biggest ones beingSwarm.Game.CESK
andSwarm.Game.Robot
. But alsoSwarm.Game.Entity
perhaps, andSwarm.Game.Exception
...
0bdeba6
to
699e42e
Compare
I've now renamed it to
The issue is that |
On that note, would it be possible to meet our needs by using just simple type parameters in the |
445ad9c
to
5bd4345
Compare
Right, but if we let modules get slurped into libraries they don't logically belong in just because of dependency issues, that kind of defeats the whole purpose of splitting up the codebase into sublibraries. (To be clear, I see the purposes of splitting into sublibraries as (1) enforcing abstraction boundaries, so we can't just import any module into any other module, and (2) making it easier to navigate the codebase.)
First of all, just to make sure I understand what you mean by "using just simple type parameters", do you have in mind something like this?
This would certainly work. But the benefits of the current code with type families as opposed to the above are as follows:
|
This actually makes a lot of sense to me --- a template robot should not really have a |
For the sake of argument, what if we bundled all of the differentiated fields into a single field with parameterized type, such that we have a toplevel parameterized type
and
|
That would be annoying since we would have to either edit every place we use one of those fields to add an extra lens to get down through the nested record, or else create some custom lenses for referring to the nested fields. Well, I guess some custom lenses wouldn't be that bad. But I still don't see what the benefit would be. What's wrong with the type families? |
PracticallyThe first issue is practical. I'm not actually sure how we could make use of type families to split what currently constitutes the Currently the
We want to purge the
where
But we're stuck in the same predicament; we still have a reference to Are type families "open" for extension, such that we can split it into two non-exhaustive definition sites?
which yielded an error:
PhilosophicallyThe second issue is philosophical and possibly moot. I sympathize with ambition of "Boring Haskell". We would like to maximize accessibility of the codebase to contributors, which IMO means limiting use of less-common language extensions. I recognize type families are used in a couple other modules the project, but we can still try to minimize the surface area for which knowledge of these advanced language features is required. A given language extension may offer some advantage over plain |
Yes, they are, if you avoid the
|
By the way, as far as "Boring Haskell" goes, I am sympathetic to that idea in general, but my primary goal with Swarm has always been to have fun writing fun code to make a fun game; maxmizing accessibility of the codebase is only a secondary goal. |
Towards #1715 and #1043. This refactoring step is a prerequisite for #1719 to extricate references to the `CESK` module from the base `RobotR` definition. In this PR: * `Swarm.Game.CESK` is imported qualified to more easily track usages * A new `RobotMachine` type family is added to parameterize the `_machine` field. * `CESK` is a new parameter to `addTRobot`
5bd4345
to
66c6047
Compare
66c6047
to
ae59077
Compare
daccd61
to
b9fc20e
Compare
1f3d8a3
to
44a2bbd
Compare
44a2bbd
to
c9b658b
Compare
@@ -12,6 +12,13 @@ | |||
-- A data type to represent robots. | |||
module Swarm.Game.Robot ( | |||
-- * Robots data | |||
RobotContextMember, | |||
_robotID, |
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.
Rather than exporting these explicit record fields, can we just use the lenses instead (which we are already exporting)? e.g. instead of _robotID r
we can write r ^. robotID
.
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.
The _robotID
and _robotLocation
field exports are pretty much only needed for the instantiateRobot
function in Swarm.Game.Robot.Concrete
. But it's unclear how lenses could substitute in that case.
Furthermore, yes, the robotID
lens for the _robotID
field is defined in swarm-scenario
, but the robotContext
and machine
lenses are necessarily defined in swarm-engine
because the Store
and CESK
types live there.
Towards #1715 and #1043
Creates a new
swarm-scenario
sublibrary intended for scenario data that is independent of game state.Planned follow-ups
This PR is already pretty large, but there is still more that can be done regarding sublibrary reorganization/splitting.
Swarm.Game.ScenarioInfo
,Swarm.Game.Tick
, andSwarm.Game.Scenario.Status
could probably be moved fromswarm-scenario
toswarm-engine
.