From 6041c1e2f31b430002745c727c98c6f76e75d1fb Mon Sep 17 00:00:00 2001 From: David Feuer Date: Thu, 29 Oct 2020 19:05:51 -0400 Subject: [PATCH] Add Apply instance for Curried --- src/Data/Functor/Day/Curried.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Data/Functor/Day/Curried.hs b/src/Data/Functor/Day/Curried.hs index 37613b7..117c92b 100644 --- a/src/Data/Functor/Day/Curried.hs +++ b/src/Data/Functor/Day/Curried.hs @@ -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 } @@ -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 #-}