Skip to content

Commit

Permalink
Merge pull request ekmett#66 from treeowl/applied-curried
Browse files Browse the repository at this point in the history
Add Apply instance for Curried
  • Loading branch information
ekmett authored Oct 28, 2023
2 parents 3e1e1b9 + 6041c1e commit 66951a0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Data/Functor/Day/Curried.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Control.Applicative
import Data.Functor.Adjunction
import Data.Functor.Day
import Data.Functor.Identity
import Data.Functor.Apply

newtype Curried g h a =
Curried { runCurried :: forall r. g (a -> r) -> h r }
Expand All @@ -46,6 +47,14 @@ instance Functor g => Functor (Curried g h) where
fmap f (Curried g) = Curried (g . fmap (.f))
{-# INLINE fmap #-}

instance (Functor g, g ~ h) => Apply (Curried g h) where
Curried mf <.> Curried ma = Curried (ma . mf . fmap (.))
{-# INLINE (<.>) #-}
#if MIN_VERSION_semigroupoids(5,2,2)
liftF2 f (Curried g) (Curried ma) = Curried (ma . g . fmap (\p q -> p . f q))
{-# INLINE liftF2 #-}
#endif

instance (Functor g, g ~ h) => Applicative (Curried g h) where
pure a = Curried (fmap ($ a))
{-# INLINE pure #-}
Expand Down

0 comments on commit 66951a0

Please sign in to comment.