Giter Club home page Giter Club logo

Comments (4)

jcpetruzza avatar jcpetruzza commented on September 25, 2024

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.

Shimuuar avatar Shimuuar commented on September 25, 2024

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.

jcpetruzza avatar jcpetruzza commented on September 25, 2024

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.

jcpetruzza avatar jcpetruzza commented on September 25, 2024

Release 2.0.0.0 includes these changes

from barbies.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.