Comments (4)
Thanks for bringing this up! I too saw ProductB
as a stronger "applicative", but was somehow convinced that we were in need of the the uniqueness properties that follow from the laws most of the time, so adding an intermediate ApplicativeB
class was not worth it.
So I went to see those places where I thought we were using this, and ended up with the exact opposite conclusion: ProductB
just captures those types whose unique "applicative" instance can be generated automatically, but I don't think we are actually using the extra "uniqueness" guarantees anywhere else. This is great, I wished I had noticed it before
So, how should an ApplicativeB
class look like? I don't think we can have a direct equivalent of <*>
(apply
) without something like impredicative-types. So without apply
, this would be probably better named MonoidalB
.
class FunctorB b => MonoidalB b where
bunit :: b Unit
bprod :: b f -> b g -> b (f `Product` g)
With laws (following Applicative programming with effects)
- Naturality of
bprod
:
bmap (hf ** hg) (bf `bprod` bg) = bmap hf bf `bprod` bmap hg bg
where
(**) :: (forall a. f a -> f' a)
-> (forall a. g a -> g' a)
-> (f `Product` g) a
-> (f' `Product` g') a
hf ** hg (Pair fa ha) = Pair (hf fa) (hg ga)
- Left/right identity:
bmap (\(Pair _ ga) -> ga) (bunit `bprod` bg) = bg
bmap (\(Pair fa _) -> fa) (bf `bprod` bunit) = bf
- Associativity:
bmap (\(Pair fa (Pair ga ha)) -> Pair (Pair fa ga) ha) (bf `bprod` (bg `bprod` bh)) = (bf `bprod` bg) `bprod` bh
from barbies.
I think ProductB
is a different kinded applicative (provided that we relax its laws). We can't define analog of <*>
so have to use bprod
. And buniq
and bunit
are equivalent:
bunit = buniq Unit
buniq f = bmap (\_ -> f) bunit
Should we use buinq
we'll have to change identity laws. This should work I think:
bmap (\(Pair _ ga) -> ga) (buniq Unit `bprod` bg) = bg
bmap (\(Pair fa _) -> fa) (bf `bprod` buniq Unit) = bf
So we already have an applicative. Its name obscures in connection to Applicative type class and maybe it should be renamed but I have no opinion on that. All in all only thing needed to add Applicative is to change documentation.
P.S. It always amazed me how much one can deduce just by looking at documentation!
from barbies.
This is now fixed on master
. ProductB
was renamed to ApplicativeB
(also ProductBC
got removed, wasn't really needed these days). I think I managed to do this without completely breaking backwards compatibility: Data.Barbie
is now deprecated but should be exposing the previous API.
from barbies.
Release 2.0.0.0
includes these changes
from barbies.
Related Issues (20)
- Higher-order functors are defined in barbies, parameterized-utils, rank2classes, category-extras... HOT 10
- Nested or recursive barbies? HOT 6
- Type errors on GHC 8.8 HOT 2
- Support for capability-style records HOT 1
- Does not compile with ghc 8.8.1 HOT 2
- Field name API? HOT 1
- Template Haskell helper HOT 3
- Lifting Semigroup and Monoid instance HOT 4
- Pushing applicative effects in? HOT 30
- Expand the Wear type family a bit HOT 13
- bzipWithCF HOT 4
- ConstraintsT applied to type parameter? HOT 2
- Compilation failure on GHC 9 HOT 3
- Add `Co` constructor for turning products into sums and vice versa HOT 11
- Release 2.0.3 to Hackage HOT 1
- Couple things that might be useful to have HOT 9
- Tests fail to build on ghc 9.2.1 HOT 4
- Compilation error on GHC 9.2.2 HOT 2
- `ConstraintsB` can't be derived for data family? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from barbies.