purescript / purescript-semirings

Semiring instances and functions
BSD 3-Clause "New" or "Revised" License
9 stars 8 forks source link

added boolean instance #3

Closed cryogenian closed 9 years ago

paf31 commented 9 years ago

Looks cool, but there are two tricky things about this:

  1. It's an orphan instance.
  2. There are at least two equally valid Boolean instances: take yours, and flip (&&) and (||) and you'll get a second.

I think we should introduce two newtypes to solve both these issues.

cryogenian commented 9 years ago

I'll add these newtypes, any ideas how to name them?

paf31 commented 9 years ago

Maybe Conjunctive and Disjunctive? Using the BoolLike instances might be nice too.

cryogenian commented 9 years ago

ok, then if && stands for * it will be Conjunctive I suppose?

paf31 commented 9 years ago

Yes, it's still a bit ambiguous. I was thinking of http://en.wikipedia.org/wiki/Conjunctive_normal_form vs http://en.wikipedia.org/wiki/Disjunctive_normal_form. Identifying the appropriate thing with (a * b * ...) + (c * d * ...) + ... (somewhat arbitrarily), I think Conjunctive ought to mean && as +.

I don't think this is a great naming scheme though. Most Haskell libs only define one instance, for Bool. The problem there is that Semiring isn't strong enough to define a Dual as another Semiring. We would need a DistributiveLattice class or something (probably also useful).

garyb commented 9 years ago

Well, BoolLike is due to be reformed to involve lattice at some point isn't it? (purescript/purescript#907) Maybe we should figure that out if we're doing this now.

paf31 commented 9 years ago

Sounds good to me.

cryogenian commented 9 years ago

added newtypes