-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
status: needs more infoThis issue needs more info before any action can be done.This issue needs more info before any action can be done.
Description
A Semiring requires commutative addition, but the addition operation for Free is list concatenation, which is not commutative.
It looks like Free is an encoding of the idea described in the wikipedia article on Semirings
- Given an alphabet (finite set) Σ, the set of formal languages over Σ (subsets of Σ∗) is a semiring with product induced by string concatenation and addition as the union of languages (i.e. simply union as sets). The zero of this semiring is the empty set (empty language) and the semiring's unit is the language containing as its sole element the empty string.[12]
- Generalising the previous example (by viewing Σ∗ as the free monoid over Σ), take M to be any monoid; the power set P M of all subsets of M forms a semiring under set-theoretic union as addition and set-wise multiplication.
If this is what is desired, perhaps a better encoding would be
instance Monoid m => Semiring (Set m) where
zero = Set.empty
add = Set.union
one = Set.singleton mempty
mul x y = Set.fromFoldable $ lift2 (<>) (Set.toUnfoldable x) (Set.toUnfoldable y :: Array m)or a newtype over this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status: needs more infoThis issue needs more info before any action can be done.This issue needs more info before any action can be done.