From 42bc88b0d1a7ad6490ecf985a29b2af51952caa9 Mon Sep 17 00:00:00 2001 From: Ryan Hendrickson Date: Thu, 12 Jun 2025 01:21:05 -0400 Subject: [PATCH] Yoneda: More stack-efficient (.>) and (*>) --- src/Data/Functor/Yoneda.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Data/Functor/Yoneda.hs b/src/Data/Functor/Yoneda.hs index 28a18ce..510615a 100644 --- a/src/Data/Functor/Yoneda.hs +++ b/src/Data/Functor/Yoneda.hs @@ -113,12 +113,16 @@ instance Functor (Yoneda f) where instance Apply f => Apply (Yoneda f) where Yoneda m <.> Yoneda n = Yoneda (\f -> m (f .) <.> n id) {-# INLINE (<.>) #-} + Yoneda m .> Yoneda n = Yoneda (\f -> m id .> n f) + {-# INLINE (.>) #-} instance Applicative f => Applicative (Yoneda f) where pure a = Yoneda (\f -> pure (f a)) {-# INLINE pure #-} Yoneda m <*> Yoneda n = Yoneda (\f -> m (f .) <*> n id) {-# INLINE (<*>) #-} + Yoneda m *> Yoneda n = Yoneda (\f -> m id *> n f) + {-# INLINE (*>) #-} instance Foldable f => Foldable (Yoneda f) where foldMap f = foldMap f . lowerYoneda