Skip to content

Commit

Permalink
Add Applicative for Forget (#107)
Browse files Browse the repository at this point in the history
This adds an Applicative instance for Forget, making it a lax monoidal profunctor in line with its Monoid instance.
  • Loading branch information
echatav authored Nov 3, 2023
1 parent 2c9fd4c commit 3fb1953
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Data/Profunctor/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,14 @@ instance Semigroup r => Semigroup (Forget r a b) where
instance Monoid r => Monoid (Forget r a b) where
mempty = Forget mempty
{-# INLINE mempty #-}

-- | Via @Monoid r => (a -> r)@
--
-- >>> let printer = (,) <$> fst `lmap` Forget id <*> snd `lmap` Forget show
-- >>> runForget printer ("string",True)
-- "stringTrue"
instance Monoid r => Applicative (Forget r a) where
pure _ = Forget mempty
{-# INLINE pure #-}
Forget f <*> Forget g = Forget (f <> g)
{-# INLINE (<*>) #-}

0 comments on commit 3fb1953

Please sign in to comment.