| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Unison.Util.Nametree
Synopsis
- data Nametree a = Nametree {
- value :: !a
- children :: !(Map NameSegment (Nametree a))
- traverseNametreeWithName :: Applicative f => ([NameSegment] -> a -> f b) -> Nametree a -> f (Nametree b)
- unfoldNametree :: (a -> (b, Map NameSegment a)) -> a -> Nametree b
- unionWith :: (a -> a -> a) -> Nametree a -> Nametree a -> Nametree a
- flattenNametree :: forall a b. Ord b => (a -> Map NameSegment b) -> Nametree a -> BiMultimap b Name
- flattenNametrees :: (Ord term, Ord typ) => Nametree (DefnsF (Map NameSegment) term typ) -> Defns (BiMultimap term Name) (BiMultimap typ Name)
- unflattenNametree :: Ord a => Map Name a -> Nametree (Map NameSegment a)
- unflattenNametrees :: (Ord term, Ord typ) => DefnsF (Map Name) term typ -> Nametree (DefnsF (Map NameSegment) term typ)
Nametree
A nametree has a value, and a collection of children nametrees keyed by name segment.
Instances
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.