HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelanguage-nix-2.2.0Haskell2010

Language.Nix.Identifier

  • 1 type
  • 5 values
  • Packagelanguage-nix-2.2.0
  • Exports6
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceIdentifier.hs
newtypenewtype Identifier
#

Identifiers in Nix are essentially strings. They can be constructed (and viewed) with the ident isomorphism. For the sake of convenience, Identifiers are an instance of the IsString class.

Reasonable people restrict themselves to identifiers of the form [a-zA-Z_][a-zA-Z0-9_'-]*, because these don't need quoting. The methods of the Text class can be used to parse and pretty-print an identifier with proper quoting:

Example2 expressions
pPrint (ident # "test")testpPrint (ident # "foo.bar")"foo.bar"
Property
\str -> Just (ident # str) == parseM "Ident" (quote str)
Property
\i -> Just (i :: Identifier) == parseM "Ident" (prettyShow i)
Instances11Eq, Ord, Show, IsString, Generic, NFData, …

An isomorphism that allows conversion of Identifier from/to the standard String type via review.

Property
\str -> fromString str == ident # str
Property
\str -> set ident str undefined == ident # str
Property
\str -> view ident (review ident str) == str
valuequote :: String -> String
#

Helper function to quote a given identifier string if necessary.

Example2 expressions
putStrLn (quote "abc")abcputStrLn (quote "abc.def")"abc.def"
valueneedsQuoting :: String -> Bool
#

Checks whether a given string needs quoting when interpreted as an Identifier. Simple identifiers that don't need quoting match the regular expression ^[a-zA-Z_][a-zA-Z0-9_'-]*$.