packages feed

papa-0.7.0: test/Composes.hs

{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

{- HLINT ignore "Avoid restricted function" -}
{- HLINT ignore "Evaluate" -}
{- HLINT ignore "Use max" -}
{- HLINT ignore "Use min" -}
{- HLINT ignore "Use ++" -}
{- HLINT ignore "Avoid lambda" -}
{- HLINT ignore "Read one value with the" -}
-- Reason: this module uses each name that has clashed, Papa's total maximum,
-- minimum, (!!) and head among them, so that the name must resolve; the
-- expressions are written to use the name, not to be simplified.

-- | "Papa" imports unqualified alongside every module that its
-- documentation says it does. This module compiles only if no name that
-- they export is ambiguous where it is used; every name that has clashed
-- before is used here.
module Composes (
  composes,
) where

import Control.Monad.Trans.Identity (IdentityT (runIdentityT))
import Papa
import Papa.Adjunctions (index)
import Papa.Associative.Renamed (SemigroupOp, op)
import Papa.Base.Control.Arrow (firstA, leftA, rightA, secondA)
import Papa.Base.Control.Monad.Cont ()
import Papa.Base.Control.Monad.Error ()
import Papa.Base.Control.Monad.Reader ()
import Papa.Base.Control.Monad.State ()
import Papa.Base.Control.Monad.Trans ()
import Papa.Base.Control.Monad.Writer ()
import Papa.Bifunctors.Data.Bifoldable ()
import qualified Papa.Comonad.Control.Comonad.Env as Env
import qualified Papa.Containers.Data.IntMap as IntMap
import qualified Papa.Containers.Data.IntSet as IntSet
import qualified Papa.Containers.Data.Map as Map
import qualified Papa.Containers.Data.Seq as Seq
import qualified Papa.Containers.Data.Set as Set
import Papa.Contravariant ()
import Papa.Distributive ()
import Papa.One.Renamed ()
import Papa.Polytree (Tree, levels)
import Papa.Profunctors.Renamed ()
import Papa.Selective (Over (Over), getOver, select)
import qualified Papa.Unsafe.Numeric as U
import Papa.Witherable.Renamed (wither)

-- | The names that have clashed, each used once, so that each must resolve.
composes :: [String]
composes =
  [ show (firstA (+ 1) (1 :: Int, 'x'))
  , show (secondA (+ 1) ('x', 1 :: Int))
  , show (first (+ 1) (1 :: Int, 'x'))
  , show (second (+ 1) ('x', 1 :: Int))
  , show ((show &&& show) (1 :: Int))
  , show (biconcat ("a", "b"))
  , show (concat [[1 :: Int], [2]])
  , show (concatMap show (1 :| [2 :: Int]))
  , show (concat (Just [1 :: Int]))
  , show (maximum (2 :| [1 :: Int]))
  , show (minimum (2 :| [1 :: Int]))
  , show (maximum (1 :| [2 :: Int]))
  , show (minimum (1 :| [2 :: Int]))
  , show (filter even [1, 2 :: Int])
  , show (mapMaybe (\x -> bool Nothing (Just x) (even x)) [1, 2 :: Int])
  , show (catMaybes [Just 'a', Nothing])
  , show (nonEmpty [1 :: Int])
  , show (null [()])
  , show (uncons [1 :: Int])
  , show (Env.ask (Env.env 'e' ()))
  , show (Map.fromList [('a', ())] Map.! 'a')
  , show (Set.findMin (Set.fromList "a"))
  , show (IntMap.findMin (IntMap.fromList [(1, 'a')]))
  , show (IntSet.findMax (IntSet.fromList [1]))
  , show (Seq.index (Seq.fromList "a") 0)
  , show (fmap (divideNonZero 1) (preview nonZero (2 :: Rational)))
  , show (toIntegralSized (1 :: Int) :: Maybe Word8)
  , show (fmap (divNonZero 7) (preview nonZero (2 :: Int)))
  , show (cycle ([] :: [Int]))
  , show (succ False)
  , show (Proxy :: Proxy Int)
  , show (getCompose (Compose (Just [()])))
  , show (reads "1 rest" :: [(Int, String)])
  , show ((show &&& negate) (1 :: Int))
  , show (runIdentityT (lift (Just 'a')))
  , show (chr 65)
  , show (stimes (2 :: Int) "ab")
  , show (fmap (ratioNonZero 7) (preview nonZero (2 :: Integer)))
  , show (readMaybe (pack "1") :: Maybe Int)
  , show ([1 :: Int] !? 0)
  , show ([1 :: Int] !! (0 :: Int))
  , show (singleton 'a')
  , show (unzip [(1 :: Int, 'a')])
  , show (partitionEithers [Left 'a', Right True])
  , show (the head ('a' :| "bc"))
  , show (getSum (Sum (1 :: Int) <> Sum 2))
  , show (getZipList (ZipList "a"))
  , show (lookup 'a' [('a', ())])
  , show (fst ('a', ()))
  , show ((ask :: Char -> Char) 'r')
  , show (runIdentity (wither (\x -> Identity (Just x)) "ab"))
  , show (getConst (contramap ord (Const "c" :: Const String Int)) :: String)
  , show (dimap ord show (+ 1) 'a')
  , show (runIdentity (select (Identity (Left 'a')) (Identity ord)))
  , show (index (Identity 'a') ())
  , show (const () (levels :: Tree [] Int Char -> [[Either Int Char]]))
  , show (getOver (Over "o" :: Over String Int))
  , show (const () (op (+) :: SemigroupOp Int Int))
  , show (userError "u")
  , show (U.div 7 (2 :: Int), (U./) 1 (2 :: Double), (U.%) 1 (2 :: Integer))
  , show (pow (2 :: Int) 3, maximumBy compare (1 :| [2 :: Int]), succ (1 :: Integer))
  , show (fromLeft 'z' (Left 'a' :: Either Char Int), preview right (Right 'b' :: Either Int Char))
  , show (leftA (+ 1) (Left 1 :: Either Int Char), rightA (+ 1) (Right 1 :: Either Char Int))
  , show (the _1 ('a', ()))
  , show (pack "t" :: Text, encodeUtf8 (pack "b") :: ByteString, (fromString "s" :: String))
  , show (Map.empty :: Map Int Char, Set.empty :: Set Int, IntMap.empty :: IntMap Char, IntSet.empty :: IntSet, Seq.empty :: Seq Int)
  , show (runState (modify (+ 1) *> gets (* 2)) (1 :: Int))
  , show (runReader (asks (+ 1)) (1 :: Int), runExcept (throwError 'e' :: Except Char Int))
  , show (swap ('a', ()), coerce (Sum (1 :: Int)) :: Int)
  , show (preview (nonZero . divisor) (3 :: Int))
  , show (nubOrd "abca", nubOrdOn ord "ab", nubInt [1, 1 :: Int], nubIntOn id [2, 2 :: Int], nub "aa")
  , show (has (errorType . _NoSuchThing) (userError "u"), the errorHandle (userError "u"), the description (userError "u"), the location (userError "u"), the fileName (userError "u"))
  , show (has _ArithException (toException Overflow), has (exception :: Prism' SomeException ArithException) (toException Overflow))
  , show (const () (catch :: IO () -> (IOException -> IO ()) -> IO ()), const () (handle :: (IOException -> IO ()) -> IO () -> IO ()), const () (try :: IO () -> IO (Either IOException ())))
  , show (const () (trying _IOException (pure ()) :: IO (Either IOException ())), const () (catching _IOException (pure ()) (const (pure ())) :: IO ()), const () (handling _IOException (const (pure ())) (pure ()) :: IO ()))
  , show (const () (bracket (pure ()) pure pure), const () (bracket_ (pure ()) (pure ()) (pure ())), const () (bracketOnError (pure ()) pure pure), const () (finally (pure ()) (pure ())), const () (onException (pure ()) (pure ())))
  , show (const () (mask_ (pure ())), const () (uninterruptibleMask_ (pure ())), const () getMaskingState, const () (forkFinally (pure ()) (const (pure ()))), const () (throwTo :: ThreadId -> ArithException -> IO ()))
  , show (const () (openFile "/dev/null" ReadMode), const () (withFile "/dev/null" ReadMode hClose), const () (hFlush stdout), const () (hIsEOF stderr), const () (hSetBuffering stdout NoBuffering), const () (exceptIO (pure ())))
  , show (const () (throwsIn :: IO ()), const () (triesIn :: IO (Either () ())), const () (masksIn :: IO ()))
  , show (const () (newIORef () >>= \r -> modifyIORef' r id *> atomicModifyIORef' r (\x -> (x, x)) *> atomicWriteIORef r ()))
  ]

-- | The class of lens's 'throwingM', in scope.
throwsIn :: (MonadThrow m) => m ()
throwsIn =
  throwingM _Overflow ()

-- | The class of lens's 'trying', in scope.
triesIn :: (MonadCatch m) => m (Either () ())
triesIn =
  trying _Overflow (pure ())

-- | The class of masking in the @exceptions@ package, in scope.
masksIn :: (MonadMask m) => m ()
masksIn =
  pure ()