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

Newtype to wrap any Semialign into a Semigroup #178

Open
AlexandreTunstall opened this issue Oct 27, 2022 · 0 comments
Open

Newtype to wrap any Semialign into a Semigroup #178

AlexandreTunstall opened this issue Oct 27, 2022 · 0 comments

Comments

@AlexandreTunstall
Copy link

The Ap newtype wrapper provides a way of using an Applicative instance as a Monoid instance.
I think a similar thing can be done for Semialign and Align.

newtype Al f a = Al { getAl :: f a }

instance (Semialign f, Semigroup a) => Semigroup (Al f a) where
    Al a <> Al b = Al (salign a b)

instance (Align f, Semigroup a) => Monoid (Al f a) where
    mempty = Al nil

The Monoid laws should follow from salign being associative and nil being an identity of salign.

I haven't looked at other type classes, but perhaps this admits instances for them too.

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

No branches or pull requests

1 participant