ekmett / bifunctors

Haskell 98 bifunctors, bifoldables and bitraversables
Other
57 stars 42 forks source link

Biap : Biapplicative :: Ap : Applicative #80

Closed Icelandjack closed 4 years ago

Icelandjack commented 4 years ago

Since Ap got added to base I think it's worth adding it here, in tagless style

class Lit a where lit :: Int -> a
class Add a where add :: a -> a -> a

you sometimes want to lift operations over a pairs or something similar, then I prefer attaching that behaviour to Biap and deriving via it

instance (Biapplicative bi, Lit a, Lit b) => Lit (Biap bi a b) where lit n = bipure (lit n) (lit n)
instance (Biapplicative bi, Add a, Add b) => Add (Biap bi a b) where add = biliftA2 add add

Open questions

Icelandjack commented 4 years ago

It passes now, how does it look?

RyanGlScott commented 4 years ago

Thanks again!

Icelandjack commented 4 years ago

That was exhausting. I'm happy to see it accepted!

ekmett commented 4 years ago

I have to admit I'm struggling a bit to understand why this library is the right home for these.

ekmett commented 4 years ago

Oh, "Biapplicative", not those classes. Okay. Still a bit of a mess, but better.

Icelandjack commented 4 years ago

Biap felt like a natural progression of Ap so I figured it should be in bifunctors with Biapplicative. But the motivation above is a bit crap I know. Should Data.Bifunctor.Biap stay or change?