-
Notifications
You must be signed in to change notification settings - Fork 40
Add newtype 'AsMovable' to derive Consumable and Dupable from Movable #357
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
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.
I guess that I'm seeing formatting here because of the fact that this isn't based on #355 ? You will have silly conflict, probably.
Looking good, though 🙂 I like seeing -100 net lines.
instance Movable a => Consumable (AsMovable a) where | ||
consume (AsMovable x) = | ||
move x & \case | ||
Ur x' -> () | ||
|
||
instance Movable a => Dupable (AsMovable a) where | ||
dupV (AsMovable x) = | ||
move x & \case | ||
Ur x' -> Data.pure (AsMovable x') |
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.
Just to outline an unimportant alternative: you could have given an instance instance Movable a => Movable (AsMovable a)
, and used it to save a little space in the Consumable
and Dupable
instances.
It doesn't change the generated code, and the code is still very short as it stands; I just wanted to point out that the possibility exists.
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.
Oh, I didn't know it was possible to do so, and it looks clearer to me with instance Movable a => Movable (AsMovable a)
, so I'll add it
EDIT: I tried to implement it, but now I don't see what can be removed from Consumable
and Dupable
instances after adding a Movable
instance for AsMovable
🤔
|
||
instance Dupable () where | ||
dupV () = Data.pure () | ||
deriving via (AsMovable ()) instance Dupable () |
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.
Since I'm doing trivial comments: I'm voting removing the empty line between two deriving instance
one-liners.
@@ -426,24 +313,36 @@ instance Prelude.Traversable Ur where | |||
|
|||
-- Some stock instances | |||
deriving instance Consumable a => Consumable (Sum a) | |||
|
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.
Ah, but I see some such lines have been added. Is that an Ormolu thing?
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.
As you guessed it, it is an ormolu thing. Maybe I could rewrite it in the "packed" style (so as to make the diff cleaner), as PR #355 will ormolize the whole codebase later?
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.
It would have been preferable. But it's probably not worth the time investment now.
a770788
to
dd11d76
Compare
No description provided.