1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution
.Types
.PackageName
13 import Distribution
.Compat
.Prelude
14 import Distribution
.Utils
.ShortText
17 import Distribution
.Parsec
18 import Distribution
.Pretty
19 import qualified Text
.PrettyPrint
as Disp
23 -- Use 'mkPackageName' and 'unPackageName' to convert from/to a
26 -- This type is opaque since @Cabal-2.0@
29 newtype PackageName
= PackageName ShortText
30 deriving (Generic
, Read, Show, Eq
, Ord
, Typeable
, Data
)
32 -- | Convert 'PackageName' to 'String'
33 unPackageName
:: PackageName
-> String
34 unPackageName
(PackageName s
) = fromShortText s
37 unPackageNameST
:: PackageName
-> ShortText
38 unPackageNameST
(PackageName s
) = s
40 -- | Construct a 'PackageName' from a 'String'
42 -- 'mkPackageName' is the inverse to 'unPackageName'
44 -- Note: No validations are performed to ensure that the resulting
45 -- 'PackageName' is valid
48 mkPackageName
:: String -> PackageName
49 mkPackageName
= PackageName
. toShortText
51 -- | Construct a 'PackageName' from a 'ShortText'
53 -- Note: No validations are performed to ensure that the resulting
54 -- 'PackageName' is valid
57 mkPackageNameST
:: ShortText
-> PackageName
58 mkPackageNameST
= PackageName
63 instance IsString PackageName
where
64 fromString
= mkPackageName
66 instance Binary PackageName
67 instance Structured PackageName
69 instance Pretty PackageName
where
70 pretty
= Disp
.text
. unPackageName
72 instance Parsec PackageName
where
73 parsec
= mkPackageName
<$> parsecUnqualComponentName
75 instance NFData PackageName
where
76 rnf
(PackageName pkg
) = rnf pkg