-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-level sets -- -- Please see the README on GitHub at -- https://github.com/isovector/type-sets#readme @package type-sets @version 0.1.0.0 module Type.Set -- | A binary search tree. When -XDataKinds is turned on, this -- becomes the backbone of the type-level set. -- --
--   >>> type MySet = Insert Bool (Insert String (Insert (Maybe Int) 'Empty))
--   
data TypeSet a Empty :: TypeSet a Branch :: a -> TypeSet a -> TypeSet a -> TypeSet a -- | O(log n). Determine membership in the 'TypeSet.' type family Member (t :: k) (bst :: TypeSet k) :: Bool -- | O(log n). Insert an element into the TypeSet. type family Insert (t :: k) (bst :: TypeSet k) :: TypeSet k -- | O(log n). Remove an element from the TypeSet. type family Remove (t :: k) (bst :: TypeSet k) :: TypeSet k -- | O(m log n) for Merge m n; put your smaller set on the -- left side. Merge two TypeSets together. type family Merge (small :: TypeSet k) (big :: TypeSet k) :: TypeSet k -- | O(log n). Compute a [Side] which finds the -- desired element in the tree. The result of this can be passed to -- Follow in order to look up the same element again later. type family Locate (t :: k) (bst :: TypeSet k) :: [Side] -- | O(log n). Follow the result of a Locate to get a -- particular element in the tree. type family Follow (ss :: [Side]) (bst :: TypeSet k) :: k -- | Either left or right down a path. data Side L :: Side R :: Side instance GHC.Show.Show Type.Set.Side instance GHC.Classes.Ord Type.Set.Side instance GHC.Classes.Eq Type.Set.Side module Type.Set.Variant -- | A Variant is like an Either, except that it can store -- any of the types contained in the TypeSet. You can use -- toVariant to construct one, and fromVariant to pattern -- match it out. data Variant (v :: TypeSet *) [Variant] :: SSide ss -> Follow ss v -> Variant v -- | A proof that the set bst contains type t. class Has t bst -- | Inject a t into a Variant. toVariant :: Has t bst => t -> Variant bst -- | Attempt to project a Variant into t. This might fail, -- because there is no guarantee that the Variant actually -- contains t. -- -- You can use decompRoot instead of this function if you'd like a -- proof that the Variant doesn't contain t in the case -- of failure. fromVariant :: Has t bst => Variant bst -> Maybe t -- | Like fromVariant, but decomposes the Variant into its -- left and right branches, depending on where t is. decompRoot :: Variant ( 'Branch t lbst rbst) -> Split t lbst rbst data Split t lbst rbst Root :: t -> Split t lbst rbst LSplit :: Variant lbst -> Split t lbst rbst RSplit :: Variant rbst -> Split t lbst rbst -- | Weaken a Variant so that it can contain something else. weaken :: forall t bst. Variant bst -> Variant (Insert t bst) -- | A proof that inserting into a bst doesn't affect the position -- of anything already in the tree. proveFollowInsert :: Follow ss (Insert t bst) :~: Follow ss bst -- | Singletons for Sides. data SSide (ss :: [Side]) [SNil] :: SSide '[] [SL] :: SSide ss -> SSide ( 'L : ss) [SR] :: SSide ss -> SSide ( 'R : ss) -- | Get a singleton for a list of Sides. class FromSides (ss :: [Side]) fromSides :: FromSides ss => SSide ss instance (Type.Set.Follow (Type.Set.Locate t bst) bst Data.Type.Equality.~ t, Type.Set.Variant.FromSides (Type.Set.Locate t bst)) => Type.Set.Variant.Has t bst instance Type.Set.Variant.FromSides '[] instance Type.Set.Variant.FromSides ss => Type.Set.Variant.FromSides ('Type.Set.L : ss) instance Type.Set.Variant.FromSides ss => Type.Set.Variant.FromSides ('Type.Set.R : ss) instance Data.Type.Equality.TestEquality Type.Set.Variant.SSide