{-# language NoImplicitPrelude, DoAndIfThenElse, OverloadedStrings, ExtendedDefaultRules #-}
{-# LANGUAGE CPP #-}
module IHaskellPrelude (
  module IHaskellPrelude,
  module X,

  -- Select reexports
  Data.Typeable.Typeable,
  Data.Typeable.cast,

  Data.Typeable.Proxy,

  GHC.Exts.IsString,
  GHC.Exts.IsList,

  System.IO.hPutStrLn,
  System.IO.hPutStr,
  System.IO.hPutChar,
  System.IO.hPrint,
  System.IO.stdout,
  System.IO.stderr,
  System.IO.stdin,
  System.IO.getChar,
  System.IO.getLine,
  System.IO.writeFile,
  System.IO.Handle,

  System.IO.Strict.readFile,
  System.IO.Strict.getContents,
  System.IO.Strict.hGetContents,

  Control.Exception.catch,
  Control.Exception.SomeException,

  Control.Applicative.Applicative(..),
  Control.Applicative.ZipList(..),
  (Control.Applicative.<$>),

  Control.Concurrent.MVar.MVar,
  Control.Concurrent.MVar.newMVar,
  Control.Concurrent.MVar.newEmptyMVar,
  Control.Concurrent.MVar.isEmptyMVar,
  Control.Concurrent.MVar.readMVar,
  Control.Concurrent.MVar.takeMVar,
  Control.Concurrent.MVar.putMVar,
  Control.Concurrent.MVar.modifyMVar,
  Control.Concurrent.MVar.modifyMVar_,

  Data.IORef.IORef,
  Data.IORef.readIORef,
  Data.IORef.writeIORef,
  Data.IORef.modifyIORef',
  Data.IORef.newIORef,



  -- Miscellaneous names
  Data.Map.Map,
  GHC.IO.FilePath,
  Data.Text.Text,
  Data.ByteString.ByteString,
  Text.Printf.printf,
  Data.Function.on,
  ) where

import           Prelude

import           Data.Semigroup         as X
import           Data.Monoid            as X hiding ((<>), First(..), Last(..))
import           Data.Tuple             as X
import           Control.Monad          as X
import           Data.Maybe             as X
import           Data.Either            as X
import           Control.Monad.IO.Class as X
import           Data.Ord               as X
import           GHC.Show               as X
import           GHC.Enum               as X
import           GHC.Num                as X
import           GHC.Real               as X
import           GHC.Err                as X hiding (absentErr)
import           GHC.Base               as X hiding (Any, mapM, foldr, sequence, many, (<|>), Module(..))
import           Data.List              as X hiding (head, last, tail, init, transpose, subsequences, permutations,
                                        foldl, foldl1, maximum, minimum, scanl, scanl1, scanr, scanr1,
                                        span, break, mapAccumL, mapAccumR, dropWhileEnd, (!!),
                                        elemIndices, elemIndex, findIndex, findIndices, zip5, zip6,
                                        zip7, zipWith5, zipWith6, zipWith7, unzip5, unzip6, unzip6,
                                        delete, union, lookup, intersect, insert, deleteBy,
                                        unionBy, intersectBy, group, groupBy, insertBy,
                                        maximumBy, minimumBy, genericLength, genericDrop, genericTake,
                                        genericSplitAt, genericIndex, genericReplicate, inits, tails)

import qualified Control.Applicative
import qualified Data.Typeable
import qualified Data.IORef
import qualified Data.Map
import qualified Data.Text
import qualified Data.Text.Lazy
import qualified Data.ByteString
import qualified Data.ByteString.Lazy
import qualified Data.Function
import qualified GHC.Exts
import qualified System.IO
import qualified System.IO.Strict
import qualified GHC.IO
import qualified Text.Printf
import qualified Control.Exception
import qualified Control.Concurrent.MVar

import qualified Data.List
import qualified Prelude as P

type LByteString = Data.ByteString.Lazy.ByteString

type LText = Data.Text.Lazy.Text

headMay :: [a] -> Maybe a
headMay :: forall a. [a] -> Maybe a
headMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall a. [a] -> a
head

tailMay :: [a] -> Maybe [a]
tailMay :: forall a. [a] -> Maybe [a]
tailMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall a. [a] -> [a]
tail

lastMay :: [a] -> Maybe a
lastMay :: forall a. [a] -> Maybe a
lastMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall a. [a] -> a
last

initMay :: [a] -> Maybe [a]
initMay :: forall a. [a] -> Maybe [a]
initMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall a. [a] -> [a]
init

maximumMay :: Ord a => [a] -> Maybe a
maximumMay :: forall a. Ord a => [a] -> Maybe a
maximumMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum

minimumMay :: Ord a => [a] -> Maybe a
minimumMay :: forall a. Ord a => [a] -> Maybe a
minimumMay = forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum

wrapEmpty :: ([a] -> b) -> [a] -> Maybe b
wrapEmpty :: forall a b. ([a] -> b) -> [a] -> Maybe b
wrapEmpty [a] -> b
_ [] = forall a. Maybe a
Nothing
wrapEmpty [a] -> b
f [a]
xs = forall a. a -> Maybe a
Just ([a] -> b
f [a]
xs)

maximumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a
maximumByMay :: forall a. (a -> a -> Ordering) -> [a] -> Maybe a
maximumByMay a -> a -> Ordering
_ [] = forall a. Maybe a
Nothing
maximumByMay a -> a -> Ordering
f [a]
xs = forall a. a -> Maybe a
Just (forall (t :: * -> *) a.
Foldable t =>
(a -> a -> Ordering) -> t a -> a
Data.List.maximumBy a -> a -> Ordering
f [a]
xs)

minimumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a
minimumByMay :: forall a. (a -> a -> Ordering) -> [a] -> Maybe a
minimumByMay a -> a -> Ordering
_ [] = forall a. Maybe a
Nothing
minimumByMay a -> a -> Ordering
f [a]
xs = forall a. a -> Maybe a
Just (forall (t :: * -> *) a.
Foldable t =>
(a -> a -> Ordering) -> t a -> a
Data.List.minimumBy a -> a -> Ordering
f [a]
xs)

readMay :: Read a => String -> Maybe a
readMay :: forall a. Read a => String -> Maybe a
readMay = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe a
headMay forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Read a => ReadS a
reads

putStrLn :: (MonadIO m) => String -> m ()
putStrLn :: forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
P.putStrLn

putStr :: (MonadIO m) => String -> m ()
putStr :: forall (m :: * -> *). MonadIO m => String -> m ()
putStr = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
P.putStr

putChar :: MonadIO m => Char -> m ()
putChar :: forall (m :: * -> *). MonadIO m => Char -> m ()
putChar = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> IO ()
P.putChar

print :: (MonadIO m, Show a) => a -> m ()
print :: forall (m :: * -> *) a. (MonadIO m, Show a) => a -> m ()
print = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> IO ()
P.print