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

Ch6 - Clarify Action exercises #228

Merged
merged 2 commits into from
Nov 11, 2020

Conversation

milesfrain
Copy link
Member

Fixes #200

@milesfrain milesfrain changed the title Ch6 -Clarify Action exercises Ch6 - Clarify Action exercises Nov 3, 2020
text/chapter6.md Outdated Show resolved Hide resolved
@@ -113,17 +111,11 @@ newtype Self m
instance actionSelf :: Monoid m => Action m (Self m) where
Copy link
Member Author

@milesfrain milesfrain Nov 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the Monoid constraint required here? It seems like this superclass relationship is already specified by the Action class and that it should be possible to write it like this instead:

instance actionSelf :: Action m (Self m) where

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answer:

it's required for the superclass relationship, it's not provided by the superclass relationship

mempty = Self mempty
-- These may also be written manualy
derive newtype instance showSelf :: Show m => Show (Self m)
derive newtype instance eqSelf :: Eq m => Eq (Self m)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fine to write without newtype wrapper:

derive instance eqSelf :: Eq m => Eq (Self m)

derive newtype instance showSelf :: Show m => Show (Self m)
derive newtype instance eqSelf :: Eq m => Eq (Self m)
derive newtype instance semigroupSelf :: Semigroup m => Semigroup (Self m)
derive newtype instance monoidSelf :: Monoid m => Monoid (Self m)

instance repeatActionMultSelf :: Action (Self Multiply) Int where
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be the best instance name (doesn't follow the earlier convention of just squishing everything together), although this doesn't really matter.

@milesfrain milesfrain merged commit 6e5a715 into purescript-contrib:master Nov 11, 2020
@milesfrain milesfrain deleted the ch6-action-clarify branch November 11, 2020 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Ch6 - Clarify Action type class exercises
1 participant