Skip to content

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

Merged
merged 1 commit into from
Jan 13, 2022

Conversation

tbagrel1
Copy link
Member

No description provided.

Copy link
Member

@aspiwack aspiwack left a 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.

Comment on lines 47 to 55
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')
Copy link
Member

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.

Copy link
Member Author

@tbagrel1 tbagrel1 Jan 12, 2022

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 ()
Copy link
Member

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)

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

@tbagrel1 tbagrel1 force-pushed the tbagrel1/newtype-deriving-consumable-dupable branch from a770788 to dd11d76 Compare January 13, 2022 13:49
@tbagrel1 tbagrel1 merged commit 299fc59 into master Jan 13, 2022
@tbagrel1 tbagrel1 deleted the tbagrel1/newtype-deriving-consumable-dupable branch January 13, 2022 15:19
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

Successfully merging this pull request may close these issues.

2 participants