unison-parser-typechecker-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Codebase.Path

Synopsis

Documentation

newtype Path Source #

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.

Constructors

Path 

Fields

Instances

Instances details
Monoid Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

mempty :: Path #

mappend :: Path -> Path -> Path #

mconcat :: [Path] -> Path #

Semigroup Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

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

sconcat :: NonEmpty Path -> Path #

stimes :: Integral b => b -> Path -> Path #

IsList Path Source #

Meant for use mostly in doc-tests where it's sometimes convenient to specify paths as lists.

Instance details

Defined in Unison.Codebase.Path

Associated Types

type Item Path #

Methods

fromList :: [Item Path] -> Path #

fromListN :: Int -> [Item Path] -> Path #

toList :: Path -> [Item Path] #

Show Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

showsPrec :: Int -> Path -> ShowS #

show :: Path -> String #

showList :: [Path] -> ShowS #

Eq Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

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

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

Ord Path Source # 
Instance details

Defined in Unison.Codebase.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 #

AsEmpty Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

_Empty :: Prism' Path () #

From Path Text Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

from :: Path -> Text #

Resolve Absolute HQSplit HQSplitAbsolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Path Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Path Path Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path -> Path -> Path Source #

Cons Path Path NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

Snoc Path Path NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

type Item Path Source # 
Instance details

Defined in Unison.Codebase.Path

newtype Path' Source #

A namespace that may be either absolute or relative, This is the most general type that should be used.

Constructors

Path' 

Instances

Instances details
Show Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

showsPrec :: Int -> Path' -> ShowS #

show :: Path' -> String #

showList :: [Path'] -> ShowS #

Eq Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

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

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

Ord Path' Source # 
Instance details

Defined in Unison.Codebase.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' #

From Path' Text Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

from :: Path' -> Text #

Resolve Absolute Path' Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Path' Path' Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Path' -> Path' Source #

Resolve Path' Split' Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Split' -> Path' Source #

Resolve Path' Split' Split' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Split' -> Split' Source #

Cons Path' Path' NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

Snoc Path' Path' NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

Snoc Split' Split' NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

newtype Absolute Source #

An absolute from the current project root

Constructors

Absolute 

Fields

Instances

Instances details
Show Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Eq Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Ord Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

From Absolute Text Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

from :: Absolute -> Text #

Resolve Absolute HQSplit HQSplitAbsolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Path Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Path' Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Cons Absolute Absolute NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

Snoc Absolute Absolute NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

newtype Relative Source #

A namespace path that doesn’t necessarily start from the root. Typically refers to a path from the current namespace.

Constructors

Relative 

Fields

Instances

Instances details
Show Relative Source # 
Instance details

Defined in Unison.Codebase.Path

Eq Relative Source # 
Instance details

Defined in Unison.Codebase.Path

Ord Relative Source # 
Instance details

Defined in Unison.Codebase.Path

From Relative Text Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

from :: Relative -> Text #

Resolve Absolute Relative Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Relative Relative Relative Source # 
Instance details

Defined in Unison.Codebase.Path

Cons Relative Relative NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

Snoc Relative Relative NameSegment NameSegment Source # 
Instance details

Defined in Unison.Codebase.Path

class Resolve l r o where Source #

Methods

resolve :: l -> r -> o Source #

Instances

Instances details
Resolve Absolute HQSplit HQSplitAbsolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Path Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Path' Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Absolute Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Absolute Relative Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Resolve Path Path Path Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path -> Path -> Path Source #

Resolve Path' Path' Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Path' -> Path' Source #

Resolve Path' Split' Path' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Split' -> Path' Source #

Resolve Path' Split' Split' Source # 
Instance details

Defined in Unison.Codebase.Path

Methods

resolve :: Path' -> Split' -> Split' Source #

Resolve Relative Relative Relative Source # 
Instance details

Defined in Unison.Codebase.Path

pattern Empty :: Path Source #

pattern (:<) :: Cons b b a a => a -> b -> b infixr 5 #

pattern (:>) :: Snoc a a b b => a -> b -> a infixl 5 #

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"} :| []))

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

conversions

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' ""
""

toName' :: Path' -> Maybe Name Source #

Convert a Path' to a Name

toText :: Path -> Text Source #

Note: This treats the path as relative.

splitFromName :: Name -> Split Source #

>>> splitFromName "a.b.c"
(a.b,c)
>>> splitFromName "foo"
(,foo)

things that could be replaced with Cons instances

things that could be replaced with Snoc instances