unison-core1-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Util.Nametree

Synopsis

Nametree

data Nametree a Source #

A nametree has a value, and a collection of children nametrees keyed by name segment.

Constructors

Nametree 

Fields

Instances

Instances details
Foldable Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

fold :: Monoid m => Nametree m -> m #

foldMap :: Monoid m => (a -> m) -> Nametree a -> m #

foldMap' :: Monoid m => (a -> m) -> Nametree a -> m #

foldr :: (a -> b -> b) -> b -> Nametree a -> b #

foldr' :: (a -> b -> b) -> b -> Nametree a -> b #

foldl :: (b -> a -> b) -> b -> Nametree a -> b #

foldl' :: (b -> a -> b) -> b -> Nametree a -> b #

foldr1 :: (a -> a -> a) -> Nametree a -> a #

foldl1 :: (a -> a -> a) -> Nametree a -> a #

toList :: Nametree a -> [a] #

null :: Nametree a -> Bool #

length :: Nametree a -> Int #

elem :: Eq a => a -> Nametree a -> Bool #

maximum :: Ord a => Nametree a -> a #

minimum :: Ord a => Nametree a -> a #

sum :: Num a => Nametree a -> a #

product :: Num a => Nametree a -> a #

Traversable Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

traverse :: Applicative f => (a -> f b) -> Nametree a -> f (Nametree b) #

sequenceA :: Applicative f => Nametree (f a) -> f (Nametree a) #

mapM :: Monad m => (a -> m b) -> Nametree a -> m (Nametree b) #

sequence :: Monad m => Nametree (m a) -> m (Nametree a) #

Functor Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

fmap :: (a -> b) -> Nametree a -> Nametree b #

(<$) :: a -> Nametree b -> Nametree a #

Semialign Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

align :: Nametree a -> Nametree b -> Nametree (These a b) #

alignWith :: (These a b -> c) -> Nametree a -> Nametree b -> Nametree c #

Unzip Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

unzipWith :: (c -> (a, b)) -> Nametree c -> (Nametree a, Nametree b) #

unzip :: Nametree (a, b) -> (Nametree a, Nametree b) #

Zip Nametree Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

zip :: Nametree a -> Nametree b -> Nametree (a, b) #

zipWith :: (a -> b -> c) -> Nametree a -> Nametree b -> Nametree c #

Generic (Nametree a) Source # 
Instance details

Defined in Unison.Util.Nametree

Associated Types

type Rep (Nametree a) :: Type -> Type #

Methods

from :: Nametree a -> Rep (Nametree a) x #

to :: Rep (Nametree a) x -> Nametree a #

Show a => Show (Nametree a) Source # 
Instance details

Defined in Unison.Util.Nametree

Methods

showsPrec :: Int -> Nametree a -> ShowS #

show :: Nametree a -> String #

showList :: [Nametree a] -> ShowS #

type Rep (Nametree a) Source # 
Instance details

Defined in Unison.Util.Nametree

type Rep (Nametree a) = D1 ('MetaData "Nametree" "Unison.Util.Nametree" "unison-core1-0.0.0-Kp7ZcNnt5XdB8ImvFwyntI" 'False) (C1 ('MetaCons "Nametree" 'PrefixI 'True) (S1 ('MetaSel ('Just "value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "children") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map NameSegment (Nametree a)))))

traverseNametreeWithName :: Applicative f => ([NameSegment] -> a -> f b) -> Nametree a -> f (Nametree b) Source #

Traverse over a nametree, with access to the list of name segments (in reverse order) leading to each value.

unfoldNametree :: (a -> (b, Map NameSegment a)) -> a -> Nametree b Source #

Build a nametree from a seed value.

Flattening and unflattening

flattenNametree :: forall a b. Ord b => (a -> Map NameSegment b) -> Nametree a -> BiMultimap b Name Source #

flattenNametree organizes a nametree like

"foo" = #foo
"foo": {
  "bar" = #bar
  "bar": {
    "baz" = #baz
  }
}

into an equivalent-but-flat association between names and definitions, like

{
  "foo" = #bar,
  "foo.bar" = #bar,
  "foo.bar.baz" = #baz
}

flattenNametrees :: (Ord term, Ord typ) => Nametree (DefnsF (Map NameSegment) term typ) -> Defns (BiMultimap term Name) (BiMultimap typ Name) Source #

Like flattenNametree, but works on both the types and terms namespace at once.

unflattenNametree :: Ord a => Map Name a -> Nametree (Map NameSegment a) Source #

unflattenNametree organizes an association between names and definitions like

{
  "foo" = #bar,
  "foo.bar" = #bar,
  "foo.bar.baz" = #baz
}

into an equivalent-but-less-flat nametree, like

"foo" = #foo
"foo": {
  "bar" = #bar
  "bar": {
    "baz" = #baz
  }
}

unflattenNametrees :: (Ord term, Ord typ) => DefnsF (Map Name) term typ -> Nametree (DefnsF (Map NameSegment) term typ) Source #

Like unflattenNametree, but works on both the types and terms namespace at once.