Skip to content

Commit

Permalink
Add Apply instance for Curried
Browse files Browse the repository at this point in the history
  • Loading branch information
treeowl committed Oct 29, 2020
1 parent 148f806 commit 6041c1e
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 @@ -37,6 +37,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 @@ -45,6 +46,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 6041c1e

Please sign in to comment.