htree-0.2.0.0: a library to build and work with heterogeneous, type level indexed rose trees
Safe HaskellNone
LanguageGHC2021

Data.HTree.Tree

Description

implements a heterogeneous tree (HTree) indexed by a homogeneous type level tree (TyTree)

Synopsis

type level tree

data TyTree (k1 :: k) where Source #

a type level rose-tree that is only intended to store something of a certain kind, e.g. Type

Constructors

TyNode :: forall a. a -> TyForest a -> TyTree a infixr 4 

Instances

Instances details
HasField' strat typ t => Decide strat 'False typ ('TyNode typ' (t ': ts')) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence' :: forall {proxy :: forall k. k -> Type}. proxy strat -> proxy 'False -> Path typ ('TyNode typ' (t ': ts')) Source #

HasField' strat typ ('TyNode typ' ts) => Decide strat 'True typ ('TyNode typ' (t' ': ts)) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence' :: forall {proxy :: forall k. k -> Type}. proxy strat -> proxy 'True -> Path typ ('TyNode typ' (t' ': ts)) Source #

HasField' 'BFS typ ('TyNode typ (t ': ts)) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'BFS -> Path typ ('TyNode typ (t ': ts)) Source #

HasField' 'BFS typ ('TyNode typ ('[] :: [TyTree Type])) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'BFS -> Path typ ('TyNode typ ('[] :: [TyTree Type])) Source #

Decide 'BFS (AnyElem typ ts) typ ('TyNode typ' (t ': ts)) => HasField' 'BFS typ ('TyNode typ' (t ': ts)) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'BFS -> Path typ ('TyNode typ' (t ': ts)) Source #

HasField' 'DFS typ ('TyNode typ (t ': ts)) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'DFS -> Path typ ('TyNode typ (t ': ts)) Source #

HasField' 'DFS typ ('TyNode typ ('[] :: [TyTree Type])) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'DFS -> Path typ ('TyNode typ ('[] :: [TyTree Type])) Source #

Decide 'DFS (Not (Elem typ t)) typ ('TyNode typ' (t ': ts)) => HasField' 'DFS typ ('TyNode typ' (t ': ts)) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

evidence :: proxy 'DFS -> Path typ ('TyNode typ' (t ': ts)) Source #

(forall x. Eq x => Eq (f x), Typeable f) => Eq (ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f)) Source # 
Instance details

Defined in Data.HTree.Existential

Methods

(==) :: ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> Bool #

(/=) :: ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> Bool #

type TyForest (a :: k) = [TyTree a] Source #

a forest of TyTrees

heterogeneous tree

data HTree (f :: k -> Type) (t :: TyTree k) where Source #

a heterogeneous rose tree indexed by a TyTree

Constructors

HNode :: forall {k} (f :: k -> Type) (a :: k) (ts :: TyForest k). f a -> HForest f ts -> HTree f ('TyNode a ts) infixr 4 

Bundled Patterns

pattern HLeaf :: forall {a1} f (a2 :: a1). f a2 -> HTree f ('TyNode a2 ('[] :: [TyTree a1]))

a pattern synonym for the leaf of an HTree

Instances

Instances details
(HasField' 'BFS (Labeled l typ) t, Functor f) => HasField (l :: k) (HTree f t) (f typ) Source # 
Instance details

Defined in Data.HTree.Labeled

Methods

getField :: HTree f t -> f typ #

(forall x. Eq x => Eq (f x), Typeable f) => Eq (ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f)) Source # 
Instance details

Defined in Data.HTree.Existential

Methods

(==) :: ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> Bool #

(/=) :: ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> ETree (Has (Both (Typeable :: Type -> Constraint) Eq) f) -> Bool #

(Show (f a2), Show (HForest f t)) => Show (HTree f ('TyNode a2 t)) Source # 
Instance details

Defined in Data.HTree.Tree

Methods

showsPrec :: Int -> HTree f ('TyNode a2 t) -> ShowS #

show :: HTree f ('TyNode a2 t) -> String #

showList :: [HTree f ('TyNode a2 t)] -> ShowS #

(Eq (f a2), Eq (HForest f t)) => Eq (HTree f ('TyNode a2 t)) Source # 
Instance details

Defined in Data.HTree.Tree

Methods

(==) :: HTree f ('TyNode a2 t) -> HTree f ('TyNode a2 t) -> Bool #

(/=) :: HTree f ('TyNode a2 t) -> HTree f ('TyNode a2 t) -> Bool #

type HForest (f :: k -> Type) (ts :: TyForest k) = HList (HTree f) ts Source #

A forest of heterogeneous rose trees

mapping

value level

hmap :: forall {k} f g (t :: TyTree k). (forall (a :: k). f a -> g a) -> HTree f t -> HTree g t Source #

map a function over an HTree

hcmap :: forall {k} f g (t :: TyTree k). forall (c :: k -> Constraint) -> AllTree c t => (forall (a :: k). c a => f a -> g a) -> HTree f t -> HTree g t Source #

map a function with a constraint over an HTree

type level

type family TreeMap (f :: k -> l) (t :: TyTree k) :: TyTree l where ... Source #

map a functor over a TyTree

Equations

TreeMap (f :: k -> a) ('TyNode x ('[] :: [TyTree k]) :: TyTree k) = 'TyNode (f x) ('[] :: [TyTree a]) 
TreeMap (f :: k -> l) ('TyNode x xs :: TyTree k) = 'TyNode (f x) (ForestMap f xs) 

type family ForestMap (f :: k -> l) (t :: TyForest k) :: TyForest l where ... Source #

map a functor over a TyForest

Equations

ForestMap (_1 :: k -> l) ('[] :: [TyTree k]) = '[] :: [TyTree l] 
ForestMap (f :: k -> l) (n ': ns :: [TyTree k]) = TreeMap f n ': ForestMap f ns 

traversing

htraverse :: forall {k} h f g (t :: TyTree k). Applicative h => (forall (a :: k). f a -> h (g a)) -> HTree f t -> h (HTree g t) Source #

traverse a structure with a function

hctraverse :: forall {k} h f g (t :: TyTree k). forall (c :: k -> Constraint) -> (AllTree c t, Applicative h) => (forall (a :: k). c a => f a -> h (g a)) -> HTree f t -> h (HTree g t) Source #

traverse a structure such that a constraint holds; this is the workhorse of mapping and traversing

folding

value level

hFoldMap :: forall {k} f (t :: TyTree k) b. Semigroup b => (forall (a :: k). f a -> b) -> HTree f t -> b Source #

monoidally folds down a tree to a single value, this is similar to foldMap

hcFoldMap :: forall {k} f (t :: TyTree k) b. forall (c :: k -> Constraint) -> (AllTree c t, Semigroup b) => (forall (a :: k). c a => f a -> b) -> HTree f t -> b Source #

monoidally folds down a tree to a single value using a constraint on the element in the wrapping functor, this is similar to foldMap

hFlatten :: forall {k} (f :: k -> Type) (t :: TyTree k). HTree f t -> HList f (FlattenTree t) Source #

flatten a heterogeneous tree down to a heterogeneous list

type level

type family FlattenTree (t :: TyTree k) :: [k] where ... Source #

a type family that flattens a tree down to a list

Equations

FlattenTree ('TyNode x xs :: TyTree k) = x ': FlattenForest xs 

type family FlattenForest (f :: TyForest k) :: [k] where ... Source #

a type family that flattens a forest down to a list

Equations

FlattenForest ('[] :: [TyTree k]) = '[] :: [k] 
FlattenForest (x ': xs :: [TyTree k]) = FlattenTree x ++ FlattenForest xs 

paths into the htree and things you can do with those

data Path (k1 :: k) (t :: TyTree k) where Source #

provides evidence that an element is in the tree by providing a path to the element

Constructors

Here :: forall {k} (k1 :: k) (ts :: TyForest k). Path k1 ('TyNode k1 ts) 
Deeper :: forall {k} (k1 :: k) (b :: k) (t1 :: TyTree k) (ts :: [TyTree k]). Path k1 t1 -> Path k1 ('TyNode b (t1 ': ts)) 
Farther :: forall {k} (k1 :: k) (b :: k) (t1 :: TyTree k) (ts :: [TyTree k]). Path k1 ('TyNode b ts) -> Path k1 ('TyNode b (t1 ': ts)) 

Instances

Instances details
Show (Path typ t) Source # 
Instance details

Defined in Data.HTree.Tree

Methods

showsPrec :: Int -> Path typ t -> ShowS #

show :: Path typ t -> String #

showList :: [Path typ t] -> ShowS #

Eq (Path typ t) Source # 
Instance details

Defined in Data.HTree.Tree

Methods

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

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

replaceAt :: forall {k} (typ :: k) (t :: TyTree k) f. Path typ t -> f typ -> HTree f t -> HTree f t Source #

replace an element at a certain path.

helpful constraints

type family AllTree (c :: k -> Constraint) (ts :: TyTree k) where ... Source #

a constraint holds for all elements in the tree

Equations

AllTree (c :: k -> Constraint) ('TyNode x ts :: TyTree k) = (c x, AllForest c ts) 

class AllTree c ts => AllTreeC (c :: k -> Constraint) (ts :: TyTree k) Source #

constraint synonym for AllTree

Instances

Instances details
AllTree c ts => AllTreeC (c :: k -> Constraint) (ts :: TyTree k) Source # 
Instance details

Defined in Data.HTree.Tree

type family AllForest (c :: k -> Constraint) (t :: TyForest k) where ... Source #

a constraint holds for all elements in the forest

Equations

AllForest (c :: k -> Constraint) (xs :: TyForest k) = All (AllTreeC c) xs 

helpers for witnessing the constraints

allTopHTree :: forall {k} (f :: k -> Type) (t :: TyTree k). HTree f t -> Dict (AllTree (Top :: k -> Constraint) t) Source #

witnesses that for any HTree the constraint AllTree Top always holds

allTopHForest :: forall {k} (f :: k -> Type) (t :: TyForest k). HForest f t -> Dict (AllForest (Top :: k -> Constraint) t) Source #

witnesses that for any HForest the constraint AllForest Top always holds