language-nix-2.1.0.1: Data types and useful functions to represent and manipulate the Nix language.

Safe HaskellNone
LanguageHaskell2010

Language.Nix.Path

Synopsis

Documentation

data Path #

Paths are non-empty lists of identifiers in Nix.

>>> path # [ident # "yo"]
Path [Identifier "yo"]

Any attempt to construct the empty path throws an error:

>>> :set -XScopedTypeVariables
>>> either (\(_::SomeException) -> "empty paths are illegal") show <$> try (evaluate (path # []))
"empty paths are illegal"

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

>>> simpleParse "foo.\"foo.bar\".bar" :: Maybe Path
Just (Path [Identifier "foo",Identifier "foo.bar",Identifier "bar"])
>>> maybe empty disp (simpleParse "foo.\"foo\".\"bar\".bar" :: Maybe Path)
foo.foo.bar.bar
\p -> Just (p :: Path) == simpleParse (display p)

Paths are instances of strings and can be implicitly converted:

>>> :set -XOverloadedStrings
>>> disp $ ("yo.bar" :: Path)
yo.bar
>>> disp $ ("  yo  .  bar  " :: Path)
yo.bar

Freaky quoted identifiers are fine throughout:

>>> disp $ path # ["yo","b\"ar"]
yo."b\"ar"
>>> disp ("\"5ident\"" :: Path)
"5ident"
>>> disp $ path # ["5ident","foo.bar","foo\nbar"]
"5ident"."foo.bar"."foo\nbar"

Instances

Eq Path # 

Methods

(==) :: Path -> Path -> Bool #

(/=) :: Path -> Path -> Bool #

Ord Path # 

Methods

compare :: Path -> Path -> Ordering #

(<) :: Path -> Path -> Bool #

(<=) :: Path -> Path -> Bool #

(>) :: Path -> Path -> Bool #

(>=) :: Path -> Path -> Bool #

max :: Path -> Path -> Path #

min :: Path -> Path -> Path #

Show Path # 

Methods

showsPrec :: Int -> Path -> ShowS #

show :: Path -> String #

showList :: [Path] -> ShowS #

IsString Path # 

Methods

fromString :: String -> Path #

Generic Path # 

Associated Types

type Rep Path :: * -> * #

Methods

from :: Path -> Rep Path x #

to :: Rep Path x -> Path #

Text Path # 

Methods

disp :: Path -> Doc #

parse :: ReadP r Path #

Arbitrary Path # 

Methods

arbitrary :: Gen Path #

shrink :: Path -> [Path] #

NFData Path # 

Methods

rnf :: Path -> () #

type Rep Path # 
type Rep Path = D1 (MetaData "Path" "Language.Nix.Path" "language-nix-2.1.0.1-5JMlQxedxJIDY3gBm48epV" True) (C1 (MetaCons "Path" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Identifier])))

path :: Iso' Path [Identifier] #

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