{-# LANGUAGE CPP #-}

module Mueval.Context (
    cleanModules,
    defaultModules,
    defaultPackages,
    qualifiedModules,
) where

-----------------------------------------------------------------------------

-- | Return false if any of the listed modules cannot be found in the whitelist.
cleanModules :: [String] -> Bool
cleanModules :: [String] -> Bool
cleanModules = (String -> Bool) -> [String] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (String -> [String] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
defaultModules)

{- | Modules which we should load by default. These are of course whitelisted.
   Specifically, we want the Prelude because otherwise things are horribly
   crippled; we want SimpleReflect so we can do neat things (for said neat
   things, see
   <http://twan.home.fmf.nl/blog/haskell/simple-reflection-of-expressions.details>);
   and we want ShowFun to neuter IO stuff even more.
   The rest should be safe to import without clashes, according to the Lambdabot
   sources.
-}
defaultModules :: [String]
defaultModules :: [String]
defaultModules =
    [ String
"Prelude"
    , String
"ShowFun"
    , String
"Debug.SimpleReflect"
    , String
"Data.Function"
    , String
"Control.Applicative"
    , String
"Control.Arrow"
    , String
"Control.Monad"
    , String
"Control.Monad.Cont"
#if __GLASGOW_HASKELL__ >= 710
    , String
"Control.Monad.Except"
#else
    , "Control.Monad.Error"
#endif
    , String
"Control.Monad.Fix"
    , String
"Control.Monad.Identity"
#if !MIN_VERSION_base(4,7,0)
    , "Control.Monad.Instances"
#endif
    , String
"Control.Monad.RWS"
    , String
"Control.Monad.Reader"
    , String
"Control.Monad.State"
    , String
"Control.Monad.State"
    , String
"Control.Monad.Writer"
    , String
"Data.Array"
    , String
"Data.Bits"
    , String
"Data.Bool"
    , String
"Data.Char"
    , String
"Data.Complex"
    , String
"Data.Dynamic"
    , String
"Data.Either"
    , String
"Data.Eq"
    , String
"Data.Fixed"
    , String
"Data.Graph"
    , String
"Data.Int"
    , String
"Data.Ix"
    , String
"Data.List"
    , String
"Data.Maybe"
    , String
"Data.Monoid"
    , {- -- Commented out because they are not necessarily available. If anyone misses
         -- them, perhaps we could look into forcing a dependency on them in the Cabal
         -- file or perhaps enable them via a CLI flag. For now, we'll stash them in a comment.
                     "Control.Parallel",
                     "Control.Parallel.Strategies",
                     "Data.Number.BigFloat",
                     "Data.Number.CReal",
                     "Data.Number.Dif",
                     "Data.Number.Fixed",
                     "Data.Number.Interval",
                     "Data.Number.Natural",
                     "Data.Number.Symbolic",
                     "Math.OEIS",
      -}
      String
"Data.Ord"
    , String
"Data.Ratio"
    , String
"Data.Tree"
    , String
"Data.Tuple"
    , String
"Data.Typeable"
    , String
"Data.Word"
    , String
"System.Random"
    , String
"Test.QuickCheck"
    , String
"Text.PrettyPrint.HughesPJ"
    , String
"Text.Printf"
    ]

defaultPackages :: [String]
defaultPackages :: [String]
defaultPackages =
    [ String
"array"
    , String
"base"
    , String
"bytestring"
    , String
"containers"
    ]

{- | Borrowed from Lambdabot, this is the whitelist of modules which should be
   safe to import functions from, but which we don't want to import by
   default.
   FIXME: make these qualified imports. The GHC API & Hint currently do not
   support qualified imports.
   WARNING: You can import these with --module, certainly, but the onus is on
   the user to make sure they fully disambiguate function names; ie:

   > mueval  --module Data.Map -e "Prelude.map (+1) [1..100]"
-}
qualifiedModules :: [(String, Maybe String)]
qualifiedModules :: [(String, Maybe String)]
qualifiedModules =
    [ --                ("Control.Arrow.Transformer", Just "AT"),
      --                ("Control.Arrow.Transformer.All", Just "AT"),
      (String
"Data.ByteString", String -> Maybe String
forall a. a -> Maybe a
Just String
"BS")
    , (String
"Data.ByteString.Char8", String -> Maybe String
forall a. a -> Maybe a
Just String
"BSC")
    , (String
"Data.ByteString.Lazy", String -> Maybe String
forall a. a -> Maybe a
Just String
"BSL")
    , (String
"Data.ByteString.Lazy.Char8", String -> Maybe String
forall a. a -> Maybe a
Just String
"BSLC")
    , (String
"Data.Foldable", String -> Maybe String
forall a. a -> Maybe a
Just String
"Data.Foldable")
    , --               ("Data.Generics", Just "Data.Generics"),
      (String
"Data.IntMap", String -> Maybe String
forall a. a -> Maybe a
Just String
"IM")
    , (String
"Data.IntSet", String -> Maybe String
forall a. a -> Maybe a
Just String
"IS")
    , (String
"Data.Map", String -> Maybe String
forall a. a -> Maybe a
Just String
"M")
    , (String
"Data.Sequence", String -> Maybe String
forall a. a -> Maybe a
Just String
"Data.Sequence")
    , (String
"Data.Set", String -> Maybe String
forall a. a -> Maybe a
Just String
"S")
    , (String
"Data.Traversable", String -> Maybe String
forall a. a -> Maybe a
Just String
"Data.Traversable")
    ]