Skip to content

Commit

Permalink
Adds biapplicative operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon-b committed Jan 10, 2024
1 parent 126c1a8 commit 52bbcd9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Data/Bifunctor/Monoidal/Specialized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

module Data.Bifunctor.Monoidal.Specialized where

--------------------------------------------------------------------------------

import Control.Category.Cartesian
import Control.Category.Tensor ()
import Data.Bifunctor
import Data.Bifunctor.Monoidal
import Data.Functor.Contravariant
import Data.Profunctor
import Data.These
import Data.Void
import Prelude hiding ((&&), (||))

--------------------------------------------------------------------------------

-- | Split the input between the two arguments and multiply their outputs.
mux :: Semigroupal (->) (,) (,) (,) p => p a b -> p c d -> p (a, c) (b, d)
mux = curry combine
Expand Down Expand Up @@ -147,3 +151,17 @@ split' = split @(->) @(,)

merge' :: Either a a -> a
merge' = merge @(->) @Either

bipure :: (Bifunctor p, Unital (->) () () () p) => a -> b -> p a b
bipure a b = bimap (const a) (const b) $ introduce @_ @() @() ()

biliftA2' :: (Bifunctor m, Semigroupal (->) (,) (,) (,) m) => (a -> b -> c) -> (d -> e -> f) -> m a d -> m b e -> m c f
biliftA2' f g m1 m2 = bimap (uncurry f) (uncurry g) $ combine (m1, m2)

biapply :: (Bifunctor p, Semigroupal (->) (,) (,) (,) p) => p (a -> b) (c -> d) -> p a c -> p b d
biapply = fmap (bimap (uncurry ($)) (uncurry ($))) . mux

infixl 4 <<*>>

(<<*>>) :: (Bifunctor p, Semigroupal (->) (,) (,) (,) p) => p (a -> b) (c -> d) -> p a c -> p b d
(<<*>>) = biapply

0 comments on commit 52bbcd9

Please sign in to comment.