typeclasses / partial-semigroup

A partial binary associative operator (appendMaybe :: a → a → Maybe a)

Home Page:https://hackage.haskell.org/package/partial-semigroup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `PartialMonoid` typeclass

pniedzielski opened this issue · comments

A useful edition to this package would be the addition of a PartialMonoid typeclass that extends PartialSemigroup with identity:

class PartialSemigroup α ⇒ PartialMonoid α where
    -- | Identity of '<>?'.
    pempty ∷ α
    pempty = fromJust $ pmconcat []

    -- | Reduce a list with '<>?'.
    pmconcat ∷ [α] → Maybe α
    pmconcat = foldM (<>?) pempty

    {-# MINIMAL (pempty) | pmconcat #-}

I'm working on a package for working with Minimalist Grammars in Haskell, and I have found that both PartialSemigroup and a PartialMonoid class (taken as above from my code) simplify constructing parsers greatly.

I would be willing to take on this issue.

That sounds cool! I don't have a ton of free time for this but if you'd submit a PR I'd be glad to incorporate it. I wouldn't mind adding you as a package maintainer either, if you're up for that.

Wonderful, I'm planning on making a PR soon with this addition. I would certainly be okay being a package maintainer as well, if that makes things easier on your end.