fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.08k stars 373 forks source link

Move some derivations into coresponding algebras #188

Open safareli opened 7 years ago

safareli commented 7 years ago

Currently this are derivations separately from algebras but I think we can move them to algebras:

As discussed in #179 we should at least state that <*> = ap in Apply and Chain (or Applicative and Monad) but we should also investigate if other derivations should be moved to corresponding algebras.

bergus commented 7 years ago

Ah, I wanted to just ask the same. My confusion was especially about Bifunctors, because stating that map can be derived from bimap (or that "Bifunctor needs to implement Functor") isn't enough, it would also need to say how. Is a.map = f => a.bimap(f, identity) (not .bimap(identity, f)) a valid Functor? The laws say yes, but e.g. in Haskell it doesn't work to make Mydatatype a b to be a Functor over a. Speaking of which, Haskells Bifunctor doesn't state that second ≡ map, although it would make sense to me (and I haven't found counterexample implementations). Could there be a reason for the omission?

safareli commented 7 years ago

The list in this issue is just an outline of derivations we have. if we move them into algebras we should also show default derivation.

In case of bimap, in derivations we have map = function(f) { return this.bimap(a => a, f); } and this will work in haskell too as it's deriving map from last parameter (second).

I have just taken look at bimap and indeed there is no word about map being equal to second and as i said:

we should investigate if other derivations should be moved to corresponding algebras

One thing i know is that <*> = ap is for sure a law and others need investigation.

rpominov commented 7 years ago

Maybe what we should do is: