Skip to content

Please add Semigroup and Monoid instances #10

@sjshuck

Description

@sjshuck

[original issue 38 by @louispan]

Would it make sense to add Semigroup and Monoid instances to the transformer newtype wrappers?

See https://mail.haskell.org/pipermail/haskell-cafe/2017-March/126588.html

Eg.

instance (Applicative m, Monoid a) => Monoid (ReaderT r m a)
    mempty = pure mempty
    mappend = liftA2 mappend

instance (Applicative m, Semigroup a) => Semigroup (ReaderT r m a)
    (<>) = liftA2 (<>)

and similar for the other transformer newtype wrappers.

David Feuer notes that the Semigroup instance actually only need an "Apply" instance, but I'm not sure how you'll be able to add Apply to the transformer package.

Olaf Klinke notes that in general:

instance (Semigroup a, Applicative f) => Semigroup (f a) where
  (<>) = liftA2 (<>)

but unfortunately that will lead to overlapping instances.

Therefore, I feel adding the instances to the transformer newtypes is a good middle ground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions