Skip to content

Newtype to wrap any Semialign into a Semigroup #178

@AlexandreTunstall

Description

@AlexandreTunstall

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.

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