Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Path = Path {
- toSeq :: Seq NameSegment
- newtype Path' = Path' {}
- newtype Absolute = Absolute {
- unabsolute :: Path
- pattern AbsolutePath' :: Absolute -> Path'
- absPath_ :: Lens' Absolute Path
- newtype Relative = Relative {
- unrelative :: Path
- relPath_ :: Lens' Relative Path
- pattern RelativePath' :: Relative -> Path'
- class Resolve l r o where
- resolve :: l -> r -> o
- pattern Empty :: Path
- pattern (:<) :: Cons b b a a => a -> b -> b
- pattern (:>) :: Snoc a a b b => a -> b -> a
- singleton :: NameSegment -> Path
- uncons :: Path -> Maybe (NameSegment, Path)
- empty :: Path
- isAbsolute :: Path' -> Bool
- isRelative :: Path' -> Bool
- absoluteEmpty :: Absolute
- absoluteEmpty' :: Path'
- relativeEmpty :: Relative
- relativeEmpty' :: Path'
- currentPath :: Path'
- prefix :: Path' -> Relative -> Path'
- prefixAbs :: Absolute -> Relative -> Absolute
- prefixRel :: Relative -> Relative -> Relative
- maybePrefix :: Path' -> Path' -> Maybe Path'
- unprefix :: Absolute -> Path' -> Path
- maybePrefixName :: Path' -> Name -> Maybe Name
- prefixNameIfRel :: Path' -> Name -> Name
- unprefixName :: Absolute -> Name -> Maybe Name
- type HQSplit = (Path, HQSegment)
- type HQSplitAbsolute = (Absolute, HQSegment)
- type AbsSplit = (Absolute, NameSegment)
- type Split = (Path, NameSegment)
- type Split' = (Path', NameSegment)
- type HQSplit' = (Path', HQSegment)
- ancestors :: Absolute -> Seq Absolute
- longestPathPrefix :: Path -> Path -> (Path, Path, Path)
- isCurrentPath :: Path' -> Bool
- isRoot :: Absolute -> Bool
- isRoot' :: Path' -> Bool
- absoluteToPath' :: Absolute -> Path'
- fromList :: [NameSegment] -> Path
- fromName :: Name -> Path
- fromName' :: Name -> Path'
- fromPath' :: Path' -> Path
- unsafeParseText :: Text -> Path
- unsafeParseText' :: Text -> Path'
- toAbsoluteSplit :: Absolute -> (Path', a) -> (Absolute, a)
- toSplit' :: Path' -> Maybe (Path', NameSegment)
- toList :: Path -> [NameSegment]
- toName :: Path -> Maybe Name
- toName' :: Path' -> Maybe Name
- toText :: Path -> Text
- toText' :: Path' -> Text
- absToText :: Absolute -> Text
- relToText :: Relative -> Text
- unsplit :: Split -> Path
- unsplit' :: Split' -> Path'
- unsplitAbsolute :: (Absolute, NameSegment) -> Absolute
- nameFromHQSplit :: HQSplit -> HashQualified Name
- nameFromHQSplit' :: HQSplit' -> HashQualified Name
- nameFromSplit' :: Split' -> Name
- splitFromName :: Name -> Split
- splitFromName' :: Name -> Split'
- hqSplitFromName' :: Name -> HQSplit'
- cons :: NameSegment -> Path -> Path
- snoc :: Path -> NameSegment -> Path
- unsnoc :: Path -> Maybe (Path, NameSegment)
Documentation
A Path
is an internal structure representing some namespace in the codebase.
Foo.Bar.baz
becomes [Foo, Bar, "baz"]
.
NB: This shouldn’t be exposed outside of this module (preferPath'
, Absolute
, or Relative
), but it’s
currently used pretty widely. Such usage should be replaced when encountered.
Path | |
|
Instances
Monoid Path Source # | |
Semigroup Path Source # | |
IsList Path Source # | Meant for use mostly in doc-tests where it's sometimes convenient to specify paths as lists. |
Show Path Source # | |
Eq Path Source # | |
Ord Path Source # | |
AsEmpty Path Source # | |
Defined in Unison.Codebase.Path | |
From Path Text Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute HQSplit HQSplitAbsolute Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute Path Absolute Source # | |
Resolve Path Path Path Source # | |
Cons Path Path NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Cons :: Prism Path Path (NameSegment, Path) (NameSegment, Path) # | |
Snoc Path Path NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Snoc :: Prism Path Path (Path, NameSegment) (Path, NameSegment) # | |
type Item Path Source # | |
Defined in Unison.Codebase.Path |
A namespace that may be either absolute or relative, This is the most general type that should be used.
Instances
Show Path' Source # | |
Eq Path' Source # | |
Ord Path' Source # | |
From Path' Text Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute Path' Absolute Source # | |
Resolve Absolute Relative Path' Source # | |
Resolve Path' Path' Path' Source # | |
Resolve Path' Split' Path' Source # | |
Resolve Path' Split' Split' Source # | |
Cons Path' Path' NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Cons :: Prism Path' Path' (NameSegment, Path') (NameSegment, Path') # | |
Snoc Path' Path' NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Snoc :: Prism Path' Path' (Path', NameSegment) (Path', NameSegment) # | |
Snoc Split' Split' NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Snoc :: Prism Split' Split' (Split', NameSegment) (Split', NameSegment) # |
An absolute from the current project root
Instances
Show Absolute Source # | |
Eq Absolute Source # | |
Ord Absolute Source # | |
Defined in Unison.Codebase.Path | |
From Absolute Text Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute HQSplit HQSplitAbsolute Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute Path Absolute Source # | |
Resolve Absolute Path' Absolute Source # | |
Resolve Absolute Relative Absolute Source # | |
Resolve Absolute Relative Path' Source # | |
Cons Absolute Absolute NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Cons :: Prism Absolute Absolute (NameSegment, Absolute) (NameSegment, Absolute) # | |
Snoc Absolute Absolute NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Snoc :: Prism Absolute Absolute (Absolute, NameSegment) (Absolute, NameSegment) # |
pattern AbsolutePath' :: Absolute -> Path' Source #
A namespace path that doesn’t necessarily start from the root. Typically refers to a path from the current namespace.
Instances
Show Relative Source # | |
Eq Relative Source # | |
Ord Relative Source # | |
Defined in Unison.Codebase.Path | |
From Relative Text Source # | |
Defined in Unison.Codebase.Path | |
Resolve Absolute Relative Absolute Source # | |
Resolve Absolute Relative Path' Source # | |
Resolve Relative Relative Relative Source # | |
Cons Relative Relative NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Cons :: Prism Relative Relative (NameSegment, Relative) (NameSegment, Relative) # | |
Snoc Relative Relative NameSegment NameSegment Source # | |
Defined in Unison.Codebase.Path _Snoc :: Prism Relative Relative (Relative, NameSegment) (Relative, NameSegment) # |
pattern RelativePath' :: Relative -> Path' Source #
class Resolve l r o where Source #
Instances
singleton :: NameSegment -> Path Source #
isAbsolute :: Path' -> Bool Source #
isRelative :: Path' -> Bool Source #
currentPath :: Path' Source #
prefix :: Path' -> Relative -> Path' Source #
This always prefixes, since the secend argument can never be Absolute.
maybePrefix :: Path' -> Path' -> Maybe Path' Source #
Returns Nothing
if the second argument is absolute. A common pattern is
fromMaybe path $ maybePrefix prefix path
to use the unmodified path in that case.
unprefix :: Absolute -> Path' -> Path Source #
examples: unprefix .foo.bar .blah == .blah (absolute paths left alone) unprefix .foo.bar id == id (relative paths starting w/ nonmatching prefix left alone) unprefix .foo.bar foo.bar.baz == baz (relative paths w/ common prefix get stripped)
maybePrefixName :: Path' -> Name -> Maybe Name Source #
Returns Nothing
if the second argument is absolute. A common pattern is
fromMaybe name $ maybePrefixName prefix name
to use the unmodified path in that case.
unprefixName :: Absolute -> Name -> Maybe Name Source #
Remove a path prefix from a name.
Returns Nothing
if there are no remaining segments to construct the name from.
>>>
unprefixName (Absolute $ fromList ["base", "List"]) (Name.unsafeFromText "base.List.map")
Just (Name Relative (NameSegment {toText = "map"} :| []))
type HQSplitAbsolute = (Absolute, HQSegment) Source #
type AbsSplit = (Absolute, NameSegment) Source #
type Split = (Path, NameSegment) Source #
type Split' = (Path', NameSegment) Source #
utilities
longestPathPrefix :: Path -> Path -> (Path, Path, Path) Source #
Finds the longest shared path prefix of two paths. Returns (shared prefix, path to first location from shared prefix, path to second location from shared prefix)
>>>
longestPathPrefix ("a" :< "b" :< "x" :< Empty) ("a" :< "b" :< "c" :< Empty)
(a.b,x,c)
>>>
longestPathPrefix Empty ("a" :< "b" :< "c" :< Empty)
(,,a.b.c)
tests
isCurrentPath :: Path' -> Bool Source #
conversions
absoluteToPath' :: Absolute -> Path' Source #
fromList :: [NameSegment] -> Path Source #
unsafeParseText :: Text -> Path Source #
unsafeParseText' :: Text -> Path' Source #
Construct a Path' from a text
>>>
fromText' "a.b.c"
a.b.c
>>>
fromText' ".a.b.c"
.a.b.c
>>>
show $ fromText' ""
""
toList :: Path -> [NameSegment] Source #
unsplitAbsolute :: (Absolute, NameSegment) -> Absolute Source #
nameFromSplit' :: Split' -> Name Source #
splitFromName :: Name -> Split Source #
>>>
splitFromName "a.b.c"
(a.b,c)
>>>
splitFromName "foo"
(,foo)
splitFromName' :: Name -> Split' Source #
hqSplitFromName' :: Name -> HQSplit' Source #