1- {-# LANGUAGE BangPatterns, NamedFieldPuns, GeneralizedNewtypeDeriving #-}
1+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+
3+ {-# OPTIONS_GHC -Wno-unused-top-binds #-}
24
35module Distribution.Server.Features.Search.ExtractNameTerms (
46 extractPackageNameTerms ,
5- extractModuleNameTerms ,
67 ) where
78
89import Data.Text (Text )
@@ -14,12 +15,11 @@ import Data.Maybe (maybeToList)
1415
1516import Data.Functor.Identity
1617import Control.Monad
17- import Control.Monad.List
1818import Control.Monad.Writer
1919import Control.Monad.State
2020import Control.Applicative
2121
22-
22+ -- UNUSED:
2323extractModuleNameTerms :: String -> [Text ]
2424extractModuleNameTerms modname =
2525 map T. toCaseFold $
@@ -180,3 +180,82 @@ main = do
180180 , let mods = exposedModules lib
181181 , mod <- mods ]
182182-}
183+
184+ ------------------------------------------------------------------------
185+ -- Vendoring deprecated ListT
186+ ------------------------------------------------------------------------
187+
188+ -- Monad transformers @ListT@ got removed in @transformers-0.6.0@
189+ -- so we vendor it here.
190+ -- It does not seem worthwhile rewriting this module to not use @ListT@,
191+ -- because:
192+ --
193+ -- - It is entirely undocumented. It does not specify what the
194+ -- module is trying to achieve.
195+ --
196+ -- - Individual functions are also not documented, neither
197+ -- their invariants nor their expected behavior.
198+ --
199+ -- - The only exported function extractPackageNameTerms
200+ -- seems to be only used in a package search facility.
201+ -- Thus, it is not important from a security perspective.
202+ --
203+ -- - This module might become obsolete once package search
204+ -- is rewritten.
205+ --
206+ -- Andreas Abel, 2022-03-06
207+
208+ newtype ListT m a = ListT { runListT :: m [a ] }
209+
210+ -- | Map between 'ListT' computations.
211+ --
212+ -- * @'runListT' ('mapListT' f m) = f ('runListT' m)@
213+ mapListT :: (m [a ] -> n [b ]) -> ListT m a -> ListT n b
214+ mapListT f m = ListT $ f (runListT m)
215+ {-# INLINE mapListT #-}
216+
217+ instance (Functor m ) => Functor (ListT m ) where
218+ fmap f = mapListT $ fmap $ map f
219+ {-# INLINE fmap #-}
220+
221+ instance (Foldable f ) => Foldable (ListT f ) where
222+ foldMap f (ListT a) = foldMap (foldMap f) a
223+ {-# INLINE foldMap #-}
224+
225+ instance (Traversable f ) => Traversable (ListT f ) where
226+ traverse f (ListT a) = ListT <$> traverse (traverse f) a
227+ {-# INLINE traverse #-}
228+
229+ instance (Applicative m ) => Applicative (ListT m ) where
230+ pure a = ListT $ pure [a]
231+ {-# INLINE pure #-}
232+ f <*> v = ListT $ (<*>) <$> runListT f <*> runListT v
233+ {-# INLINE (<*>) #-}
234+
235+ instance (Applicative m ) => Alternative (ListT m ) where
236+ empty = ListT $ pure []
237+ {-# INLINE empty #-}
238+ m <|> n = ListT $ (++) <$> runListT m <*> runListT n
239+ {-# INLINE (<|>) #-}
240+
241+ instance (Monad m ) => Monad (ListT m ) where
242+ m >>= k = ListT $ do
243+ a <- runListT m
244+ b <- mapM (runListT . k) a
245+ return (concat b)
246+ {-# INLINE (>>=) #-}
247+
248+ instance (Monad m ) => MonadPlus (ListT m ) where
249+ mzero = ListT $ return []
250+ {-# INLINE mzero #-}
251+ m `mplus` n = ListT $ do
252+ a <- runListT m
253+ b <- runListT n
254+ return (a ++ b)
255+ {-# INLINE mplus #-}
256+
257+ instance MonadTrans ListT where
258+ lift m = ListT $ do
259+ a <- m
260+ return [a]
261+ {-# INLINE lift #-}
0 commit comments