{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.ModuleName
-- Copyright   :  Duncan Coutts 2008
-- License     :  BSD3
--
-- Maintainer  :  cabal-devel@haskell.org
-- Portability :  portable
--
-- Data type for Haskell module names.

module Distribution.ModuleName (
        ModuleName (..), -- TODO: move Parsec instance here, don't export constructor
        fromString,
        fromComponents,
        components,
        toFilePath,
        main,
        -- * Internal
        validModuleComponent,
  ) where

import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Utils.ShortText
import System.FilePath ( pathSeparator )

import Distribution.Pretty
import Distribution.Parsec

import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp

-- | A valid Haskell module name.
--
newtype ModuleName = ModuleName ShortTextLst
  deriving (ModuleName -> ModuleName -> Bool
(ModuleName -> ModuleName -> Bool)
-> (ModuleName -> ModuleName -> Bool) -> Eq ModuleName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModuleName -> ModuleName -> Bool
$c/= :: ModuleName -> ModuleName -> Bool
== :: ModuleName -> ModuleName -> Bool
$c== :: ModuleName -> ModuleName -> Bool
Eq, (forall x. ModuleName -> Rep ModuleName x)
-> (forall x. Rep ModuleName x -> ModuleName) -> Generic ModuleName
forall x. Rep ModuleName x -> ModuleName
forall x. ModuleName -> Rep ModuleName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModuleName x -> ModuleName
$cfrom :: forall x. ModuleName -> Rep ModuleName x
Generic, Eq ModuleName
Eq ModuleName
-> (ModuleName -> ModuleName -> Ordering)
-> (ModuleName -> ModuleName -> Bool)
-> (ModuleName -> ModuleName -> Bool)
-> (ModuleName -> ModuleName -> Bool)
-> (ModuleName -> ModuleName -> Bool)
-> (ModuleName -> ModuleName -> ModuleName)
-> (ModuleName -> ModuleName -> ModuleName)
-> Ord ModuleName
ModuleName -> ModuleName -> Bool
ModuleName -> ModuleName -> Ordering
ModuleName -> ModuleName -> ModuleName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ModuleName -> ModuleName -> ModuleName
$cmin :: ModuleName -> ModuleName -> ModuleName
max :: ModuleName -> ModuleName -> ModuleName
$cmax :: ModuleName -> ModuleName -> ModuleName
>= :: ModuleName -> ModuleName -> Bool
$c>= :: ModuleName -> ModuleName -> Bool
> :: ModuleName -> ModuleName -> Bool
$c> :: ModuleName -> ModuleName -> Bool
<= :: ModuleName -> ModuleName -> Bool
$c<= :: ModuleName -> ModuleName -> Bool
< :: ModuleName -> ModuleName -> Bool
$c< :: ModuleName -> ModuleName -> Bool
compare :: ModuleName -> ModuleName -> Ordering
$ccompare :: ModuleName -> ModuleName -> Ordering
$cp1Ord :: Eq ModuleName
Ord, ReadPrec [ModuleName]
ReadPrec ModuleName
Int -> ReadS ModuleName
ReadS [ModuleName]
(Int -> ReadS ModuleName)
-> ReadS [ModuleName]
-> ReadPrec ModuleName
-> ReadPrec [ModuleName]
-> Read ModuleName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ModuleName]
$creadListPrec :: ReadPrec [ModuleName]
readPrec :: ReadPrec ModuleName
$creadPrec :: ReadPrec ModuleName
readList :: ReadS [ModuleName]
$creadList :: ReadS [ModuleName]
readsPrec :: Int -> ReadS ModuleName
$creadsPrec :: Int -> ReadS ModuleName
Read, Int -> ModuleName -> ShowS
[ModuleName] -> ShowS
ModuleName -> String
(Int -> ModuleName -> ShowS)
-> (ModuleName -> String)
-> ([ModuleName] -> ShowS)
-> Show ModuleName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModuleName] -> ShowS
$cshowList :: [ModuleName] -> ShowS
show :: ModuleName -> String
$cshow :: ModuleName -> String
showsPrec :: Int -> ModuleName -> ShowS
$cshowsPrec :: Int -> ModuleName -> ShowS
Show, Typeable, Typeable ModuleName
DataType
Constr
Typeable ModuleName
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ModuleName -> c ModuleName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ModuleName)
-> (ModuleName -> Constr)
-> (ModuleName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ModuleName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ModuleName))
-> ((forall b. Data b => b -> b) -> ModuleName -> ModuleName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ModuleName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ModuleName -> r)
-> (forall u. (forall d. Data d => d -> u) -> ModuleName -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ModuleName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName)
-> Data ModuleName
ModuleName -> DataType
ModuleName -> Constr
(forall b. Data b => b -> b) -> ModuleName -> ModuleName
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleName -> c ModuleName
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleName
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ModuleName -> u
forall u. (forall d. Data d => d -> u) -> ModuleName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleName -> c ModuleName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModuleName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModuleName)
$cModuleName :: Constr
$tModuleName :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
gmapMp :: (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
gmapM :: (forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ModuleName -> m ModuleName
gmapQi :: Int -> (forall d. Data d => d -> u) -> ModuleName -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ModuleName -> u
gmapQ :: (forall d. Data d => d -> u) -> ModuleName -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ModuleName -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleName -> r
gmapT :: (forall b. Data b => b -> b) -> ModuleName -> ModuleName
$cgmapT :: (forall b. Data b => b -> b) -> ModuleName -> ModuleName
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModuleName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ModuleName)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ModuleName)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModuleName)
dataTypeOf :: ModuleName -> DataType
$cdataTypeOf :: ModuleName -> DataType
toConstr :: ModuleName -> Constr
$ctoConstr :: ModuleName -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleName
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleName -> c ModuleName
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleName -> c ModuleName
$cp1Data :: Typeable ModuleName
Data)

instance Binary ModuleName

instance NFData ModuleName where
    rnf :: ModuleName -> ()
rnf (ModuleName ShortTextLst
ms) = ShortTextLst -> ()
forall a. NFData a => a -> ()
rnf ShortTextLst
ms

instance Pretty ModuleName where
  pretty :: ModuleName -> Doc
pretty (ModuleName ShortTextLst
ms) =
    [Doc] -> Doc
Disp.hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (Char -> Doc
Disp.char Char
'.') ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc
Disp.text ([String] -> [Doc]) -> [String] -> [Doc]
forall a b. (a -> b) -> a -> b
$ ShortTextLst -> [String]
stlToStrings ShortTextLst
ms))

instance Parsec ModuleName where
    parsec :: m ModuleName
parsec = [String] -> ModuleName
fromComponents ([String] -> ModuleName) -> m [String] -> m ModuleName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String -> m Char -> m [String]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
P.sepBy1 m String
component (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'.')
      where
        component :: m String
component = do
            Char
c  <- (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
P.satisfy Char -> Bool
isUpper
            String
cs <- (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch Char -> Bool
validModuleChar
            String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:String
cs)

validModuleChar :: Char -> Bool
validModuleChar :: Char -> Bool
validModuleChar Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\''

validModuleComponent :: String -> Bool
validModuleComponent :: String -> Bool
validModuleComponent []     = Bool
False
validModuleComponent (Char
c:String
cs) = Char -> Bool
isUpper Char
c
                           Bool -> Bool -> Bool
&& (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
validModuleChar String
cs

-- | Construct a 'ModuleName' from a valid module name 'String'.
--
-- This is just a convenience function intended for valid module strings. It is
-- an error if it is used with a string that is not a valid module name. If you
-- are parsing user input then use 'Distribution.Text.simpleParse' instead.
--
instance IsString ModuleName where
    fromString :: String -> ModuleName
fromString String
string = [String] -> ModuleName
fromComponents (String -> [String]
split String
string)
      where
        split :: String -> [String]
split String
cs = case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'.') String
cs of
          (String
chunk,[])     -> String
chunk String -> [String] -> [String]
forall a. a -> [a] -> [a]
: []
          (String
chunk,Char
_:String
rest) -> String
chunk String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String -> [String]
split String
rest

-- | Construct a 'ModuleName' from valid module components, i.e. parts
-- separated by dots.
fromComponents :: [String] -> ModuleName
fromComponents :: [String] -> ModuleName
fromComponents [String]
components'
    | [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
components'                     = String -> ModuleName
forall a. HasCallStack => String -> a
error String
zeroComponents
    | (String -> Bool) -> [String] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all String -> Bool
validModuleComponent [String]
components' = ShortTextLst -> ModuleName
ModuleName ([String] -> ShortTextLst
stlFromStrings [String]
components')
    | Bool
otherwise                            = String -> ModuleName
forall a. HasCallStack => String -> a
error String
badName
  where
    zeroComponents :: String
zeroComponents = String
"ModuleName.fromComponents: zero components"
    badName :: String
badName        = String
"ModuleName.fromComponents: invalid components " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall a. Show a => a -> String
show [String]
components'

-- | The module name @Main@.
--
main :: ModuleName
main :: ModuleName
main = ShortTextLst -> ModuleName
ModuleName ([String] -> ShortTextLst
stlFromStrings [String
"Main"])

-- | The individual components of a hierarchical module name. For example
--
-- > components (fromString "A.B.C") = ["A", "B", "C"]
--
components :: ModuleName -> [String]
components :: ModuleName -> [String]
components (ModuleName ShortTextLst
ms) = ShortTextLst -> [String]
stlToStrings ShortTextLst
ms

-- | Convert a module name to a file path, but without any file extension.
-- For example:
--
-- > toFilePath (fromString "A.B.C") = "A/B/C"
--
toFilePath :: ModuleName -> FilePath
toFilePath :: ModuleName -> String
toFilePath = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate [Char
pathSeparator] ([String] -> String)
-> (ModuleName -> [String]) -> ModuleName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleName -> [String]
components

----------------------------------------------------------------------------
-- internal helper

-- | Strict/unpacked representation of @[ShortText]@
data ShortTextLst = STLNil
                  | STLCons !ShortText !ShortTextLst
                  deriving (ShortTextLst -> ShortTextLst -> Bool
(ShortTextLst -> ShortTextLst -> Bool)
-> (ShortTextLst -> ShortTextLst -> Bool) -> Eq ShortTextLst
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShortTextLst -> ShortTextLst -> Bool
$c/= :: ShortTextLst -> ShortTextLst -> Bool
== :: ShortTextLst -> ShortTextLst -> Bool
$c== :: ShortTextLst -> ShortTextLst -> Bool
Eq, (forall x. ShortTextLst -> Rep ShortTextLst x)
-> (forall x. Rep ShortTextLst x -> ShortTextLst)
-> Generic ShortTextLst
forall x. Rep ShortTextLst x -> ShortTextLst
forall x. ShortTextLst -> Rep ShortTextLst x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShortTextLst x -> ShortTextLst
$cfrom :: forall x. ShortTextLst -> Rep ShortTextLst x
Generic, Eq ShortTextLst
Eq ShortTextLst
-> (ShortTextLst -> ShortTextLst -> Ordering)
-> (ShortTextLst -> ShortTextLst -> Bool)
-> (ShortTextLst -> ShortTextLst -> Bool)
-> (ShortTextLst -> ShortTextLst -> Bool)
-> (ShortTextLst -> ShortTextLst -> Bool)
-> (ShortTextLst -> ShortTextLst -> ShortTextLst)
-> (ShortTextLst -> ShortTextLst -> ShortTextLst)
-> Ord ShortTextLst
ShortTextLst -> ShortTextLst -> Bool
ShortTextLst -> ShortTextLst -> Ordering
ShortTextLst -> ShortTextLst -> ShortTextLst
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ShortTextLst -> ShortTextLst -> ShortTextLst
$cmin :: ShortTextLst -> ShortTextLst -> ShortTextLst
max :: ShortTextLst -> ShortTextLst -> ShortTextLst
$cmax :: ShortTextLst -> ShortTextLst -> ShortTextLst
>= :: ShortTextLst -> ShortTextLst -> Bool
$c>= :: ShortTextLst -> ShortTextLst -> Bool
> :: ShortTextLst -> ShortTextLst -> Bool
$c> :: ShortTextLst -> ShortTextLst -> Bool
<= :: ShortTextLst -> ShortTextLst -> Bool
$c<= :: ShortTextLst -> ShortTextLst -> Bool
< :: ShortTextLst -> ShortTextLst -> Bool
$c< :: ShortTextLst -> ShortTextLst -> Bool
compare :: ShortTextLst -> ShortTextLst -> Ordering
$ccompare :: ShortTextLst -> ShortTextLst -> Ordering
$cp1Ord :: Eq ShortTextLst
Ord, Typeable, Typeable ShortTextLst
DataType
Constr
Typeable ShortTextLst
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ShortTextLst -> c ShortTextLst)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ShortTextLst)
-> (ShortTextLst -> Constr)
-> (ShortTextLst -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ShortTextLst))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ShortTextLst))
-> ((forall b. Data b => b -> b) -> ShortTextLst -> ShortTextLst)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r)
-> (forall u. (forall d. Data d => d -> u) -> ShortTextLst -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ShortTextLst -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst)
-> Data ShortTextLst
ShortTextLst -> DataType
ShortTextLst -> Constr
(forall b. Data b => b -> b) -> ShortTextLst -> ShortTextLst
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortTextLst -> c ShortTextLst
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortTextLst
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ShortTextLst -> u
forall u. (forall d. Data d => d -> u) -> ShortTextLst -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortTextLst
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortTextLst -> c ShortTextLst
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ShortTextLst)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortTextLst)
$cSTLCons :: Constr
$cSTLNil :: Constr
$tShortTextLst :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
gmapMp :: (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
gmapM :: (forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ShortTextLst -> m ShortTextLst
gmapQi :: Int -> (forall d. Data d => d -> u) -> ShortTextLst -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ShortTextLst -> u
gmapQ :: (forall d. Data d => d -> u) -> ShortTextLst -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ShortTextLst -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortTextLst -> r
gmapT :: (forall b. Data b => b -> b) -> ShortTextLst -> ShortTextLst
$cgmapT :: (forall b. Data b => b -> b) -> ShortTextLst -> ShortTextLst
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortTextLst)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortTextLst)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ShortTextLst)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ShortTextLst)
dataTypeOf :: ShortTextLst -> DataType
$cdataTypeOf :: ShortTextLst -> DataType
toConstr :: ShortTextLst -> Constr
$ctoConstr :: ShortTextLst -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortTextLst
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortTextLst
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortTextLst -> c ShortTextLst
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortTextLst -> c ShortTextLst
$cp1Data :: Typeable ShortTextLst
Data)

instance NFData ShortTextLst where
    rnf :: ShortTextLst -> ()
rnf = (ShortTextLst -> () -> ()) -> () -> ShortTextLst -> ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip ShortTextLst -> () -> ()
seq ()

instance Show ShortTextLst where
    showsPrec :: Int -> ShortTextLst -> ShowS
showsPrec Int
p = Int -> [ShortText] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p ([ShortText] -> ShowS)
-> (ShortTextLst -> [ShortText]) -> ShortTextLst -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortTextLst -> [ShortText]
stlToList


instance Read ShortTextLst where
    readsPrec :: Int -> ReadS ShortTextLst
readsPrec Int
p = (([ShortText], String) -> (ShortTextLst, String))
-> [([ShortText], String)] -> [(ShortTextLst, String)]
forall a b. (a -> b) -> [a] -> [b]
map (([ShortText] -> ShortTextLst)
-> ([ShortText], String) -> (ShortTextLst, String)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first [ShortText] -> ShortTextLst
stlFromList) ([([ShortText], String)] -> [(ShortTextLst, String)])
-> (String -> [([ShortText], String)]) -> ReadS ShortTextLst
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> [([ShortText], String)]
forall a. Read a => Int -> ReadS a
readsPrec Int
p

instance Binary ShortTextLst where
    put :: ShortTextLst -> Put
put = [ShortText] -> Put
forall t. Binary t => t -> Put
put ([ShortText] -> Put)
-> (ShortTextLst -> [ShortText]) -> ShortTextLst -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortTextLst -> [ShortText]
stlToList
    get :: Get ShortTextLst
get = [ShortText] -> ShortTextLst
stlFromList ([ShortText] -> ShortTextLst)
-> Get [ShortText] -> Get ShortTextLst
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [ShortText]
forall t. Binary t => Get t
get

stlToList :: ShortTextLst -> [ShortText]
stlToList :: ShortTextLst -> [ShortText]
stlToList ShortTextLst
STLNil = []
stlToList (STLCons ShortText
st ShortTextLst
next) = ShortText
st ShortText -> [ShortText] -> [ShortText]
forall a. a -> [a] -> [a]
: ShortTextLst -> [ShortText]
stlToList ShortTextLst
next

stlToStrings :: ShortTextLst -> [String]
stlToStrings :: ShortTextLst -> [String]
stlToStrings = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
fromShortText ([ShortText] -> [String])
-> (ShortTextLst -> [ShortText]) -> ShortTextLst -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortTextLst -> [ShortText]
stlToList

stlFromList :: [ShortText] -> ShortTextLst
stlFromList :: [ShortText] -> ShortTextLst
stlFromList [] = ShortTextLst
STLNil
stlFromList (ShortText
x:[ShortText]
xs) = ShortText -> ShortTextLst -> ShortTextLst
STLCons ShortText
x ([ShortText] -> ShortTextLst
stlFromList [ShortText]
xs)

stlFromStrings :: [String] -> ShortTextLst
stlFromStrings :: [String] -> ShortTextLst
stlFromStrings = [ShortText] -> ShortTextLst
stlFromList ([ShortText] -> ShortTextLst)
-> ([String] -> [ShortText]) -> [String] -> ShortTextLst
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> ShortText) -> [String] -> [ShortText]
forall a b. (a -> b) -> [a] -> [b]
map String -> ShortText
toShortText