-
Notifications
You must be signed in to change notification settings - Fork 27
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
Separate left and right actions #38
base: master
Are you sure you want to change the base?
Conversation
The Action typeclass really represents left actions. This moves Action under an Action namespace with the name LeftAction. It also updates files where Action instances are defined and make them use LeftActions. It also creates a type alias Action in the old Action namespace pointing to LeftAction and act pointing to leftAct for compatibility.
Pretty much mirrors LeftAction.
Thanks! Sorry for the delayed response, I will take a look soon. |
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.
After looking this over my biggest complaint is that leaving in Action
and act
as aliases for LeftAction
and leftAct
does not actually prevent breakage: it is still going to break any existing instances of Action
, which will have to be changed to LeftAction
. (While it is possible to make an instance for a type synonym, it is not possible to make an instance of a synonym (I tried)---e.g. if we have class Foo
and then type Bar = Foo
, it is not possible to say instance Bar T where ...
.)
A proposed compromise is to simply leave the Action
class alone and add RightAction
as a new class. This has the benefit of being a much simpler change and not breaking any existing code. One might complain that it is asymmetric, but I think the asymmetry is sensible here --- left actions are much more common/natural than right actions because of the asymmetry in the way we write function application and composition. What do you think?
-- values of type @m@ act (@rightAct@) on values of another type @s@. | ||
-- Instances are required to satisfy the laws | ||
-- | ||
-- * @mempty \`rightAct\` s = s@ |
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.
These laws need to be fixed, I think they are copy-pasted from the left action laws.
-- has chosen to have instance selection for @RightAction@ driven by the | ||
-- /first/ type parameter. That is, you should never write an | ||
-- instance of the form @RightAction m SomeType@ since it will overlap | ||
-- with instances of the form @Action SomeMonoid t@. Newtype |
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.
-- with instances of the form @Action SomeMonoid t@. Newtype | |
-- with instances of the form @RightAction SomeMonoid t@. Newtype |
-- act individually. | ||
instance (Action m r, Action n r) => Action (m :+: n) r where | ||
act = appEndo . mconcat . map (Endo . either act act) . unMCo | ||
-- | Coproducts left actions on other things by having each of the components |
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.
-- | Coproducts left actions on other things by having each of the components | |
-- | Coproducts act on other things by having each of the components |
instance (Action m r, Action n r) => Action (m :+: n) r where | ||
act = appEndo . mconcat . map (Endo . either act act) . unMCo | ||
-- | Coproducts left actions on other things by having each of the components | ||
-- left actions individually. |
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.
-- left actions individually. | |
-- act individually. |
@byorgey that sounds fair to me. It happens to be a super busy week for me. So I won't be able to get to this until the weekend. Just to be clear basically what needs to be done boils down to reverting 2cead61 and fixing the bits of documentation that I screwed up in RightAction.hs. Is that correct? |
OK, given how long it took me to respond, obviously there's no rush. =)
Yes, that sounds right to me. |
Separates left and right actions as discussed in #37
Hope this is sensible. Let me know if any changes needed.
Also happy holidays!