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.Path

  • 1 type
  • 1 value
newtypenewtype Path
#

Paths are non-empty lists of identifiers in Nix.

Example1 expression
path # [ident # "yo"]Path [Identifier "yo"]

Any attempt to construct the empty path throws an error:

Example2 expressions
:set -XScopedTypeVariableseither (\(_::SomeException) -> "empty paths are illegal") show <$> Excpt.try (evaluate (path # []))"empty paths are illegal"

Paths can be pretty-printed and parsed with the Text class:

Example2 expressions
parse "Path" "foo.\"foo.bar\".bar" :: PathPath [Identifier "foo",Identifier "foo.bar",Identifier "bar"]pPrint (parse "Path" "foo.\"foo\".\"bar\".bar" :: Path)foo.foo.bar.bar
Property
\p -> Just (p :: Path) == parseM "Path" (prettyShow p)

Paths are instances of strings and can be implicitly converted:

Example3 expressions
:set -XOverloadedStringspPrint $ ("yo.bar" :: Path)yo.barpPrint $ ("  yo  .  bar" :: Path)yo.bar

Freaky quoted identifiers are fine throughout:

Example3 expressions
pPrint $ path # ["yo","b\"ar"]yo."b\"ar"pPrint ("\"5ident\"" :: Path)"5ident"pPrint $ path # ["5ident","foo.bar","foo\nbar"]"5ident"."foo.bar"."foo\nbar"
Instances11Eq, Ord, Show, IsString, Generic, NFData, …
valuepath :: Iso' Path [Identifier]
#

Use this isomorphism to construct a path from a list of identifiers, or to access that list for a given path.