purescript-deprecated/purescript-monoid

Add `Additive` and `Multiplicative` monoids

Closed this issue · 4 comments

Should we release as v0.2.0 after this, or just v0.1.6? The latter has the advantage of us not having to rerelease that massive list of things I mentioned in the issue about Num, but as this will require a new version of the compiler it sort of is a breaking change.

For reference from the other issue:

-- additive monoid
newtype Additive a = Additive a

-- multiplicative monoid
newtype Multiplicative a = Multiplicative a

instance additiveSemigroup :: (Semiring a) => Semigroup (Additive a) where 
  (<>) (Additive a) (Additive b) = Additive (a + b)

instance additiveMonoid :: (Semiring a) => Monoid (Additive a) where
  mempty = Additive zero

-- todo: Additive functor, applicative, etc.

instance multiplicativeSemigroup :: (Semiring a) => Semigroup (Multiplicative a) where 
  (<>) (Multiplicative a) (Multiplicative b) = Multiplicative (a + b)

instance multiplicativeMonoid :: (Semiring a) => Monoid (Multiplicative a) where
  mempty = Multiplicative one

-- todo: Multiplicative functor, applicative, etc. 

I think 0.2.0 makes sense.

Yet another data point in favour of moving to a packaged Prelude. As soon as rewrites are done, there's nothing stopping us from creating a purescript-prelude package and friends (purescript-eff, purescript-st, etc.) and I suggest we do it as soon as we can. Next week, rewrites will be my #1 priority now that psc-pages is done.

Fair enough.

Yeah, I'm looking forward to the minimal prelude! I guess ideally we should do the CoreImp too for the rewrites - I know that's mostly just a renamed JS AST, but we may as well take the opportunity to simplify it some where we can, and perhaps preserve Ident rather than String identifiers.

Having a traversable CoreImp seems like the easiest way to solve the overlapping module/data constructor name issue too, so there's another plus point for having it.

I think the JS AST can pretty much just be renamed, no? :) We already have the traverals we need, and I'll be implementing them in PureScript anyway for the rewrite rules.