-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient relational queries on Haskell sets. -- -- Just pick which parts of your data structures you want indexed using -- an easy to use template-haskell function. Spare yourself the need to -- write, run, and maintain code that marshalls your data to/from an -- external relational database just for efficient queries. -- happstack-ixset relies on generics and TH to spare you the boilerplate -- normally required for such tasks. @package happstack-ixset @version 0.2.1 module Happstack.Data.IxSet.Ix data Ix a IxDefault :: Ix a Ix :: (Map key (Set a)) -> Ix a con_Ix_Data :: Constr ixType_Data :: DataType ixDefaultConstr :: Constr ixConstr :: Constr ixDataType :: DataType -- | Convenience function for inserting into Maps of Sets as in the case of -- an Ix. If they key did not already exist in the Map, then a new Set is -- added transparently. insert :: (Ord a, Ord k) => k -> a -> Map k (Set a) -> Map k (Set a) -- | Convenience function for deleting from Maps of Sets If the resulting -- Set is empty, then the entry is removed from the Map delete :: (Ord a, Ord k) => k -> a -> Map k (Set a) -> Map k (Set a) instance [overlap ok] Typeable1 Ix instance [overlap ok] (Data ctx a, Sat (ctx (Ix a))) => Data ctx (Ix a) instance [overlap ok] (Default a) => Default (Ix a) instance [overlap ok] (Data a) => Data (Ix a) -- | Assume you have a type like: -- --
--   data Entry = Entry Author [Author] Updated Id Content
--     newtype Updated = Updated EpochTime
--     newtype Id = Id Int64
--     newtype Content = Content String
--     newtype Author = Author Email
--     type Email = String
--   
-- -- 1. Decide what parts of your type you want indexed, and make your type -- an instance of Indexable -- --
--   instance Indexable Entry () where
--       empty = IxSet[
--                   ,Ix (Map.empty::Map Author (Set Entry)) --out of order
--                   ,Ix (Map.empty::Map Id (Set Entry))
--                   ,Ix (Map.empty::Map Updated (Set Entry))
--                   ,Ix (Map.empty::Map Test (Set Entry)) -- bogus index
--                   ,Ix (Map.empty::Map Word (Set Entry)) -- text index
--                   ]
--       calcs entry = () -- words for text indexing purposes
--   
-- -- 3. Use insert,delete,replace and empty to build up an IxSet collection -- -- entries = foldr insert empty [e1,e2,e3,e4] entries' = -- foldr delete entries [e1,e3] entries'' = update e4 e5 -- entries -- -- 4. Use the query functions below to grab data from it. e.g. -- --
--   entries @< (Updated t1) @= (Author "john@doe.com")
--   
-- -- will find all items in entries updated earlier than t1 by -- john@doe.com. -- -- 5. Text Index -- -- If you want to do add a text index extract the words in entry and pass -- them in the calc method of the Indexable class. Then if you want all -- entries with either word1 or word2, you change the instance to -- --
--   getWords entry = let Just (Content s) =
--                                        gGet entry in map Word $ words s
--   
-- --
--   instance Indexable Entry [Word] where
--       ....
--       calcs entry = getWords entry
--   
-- -- Now you can do this query to find entries with any of the words -- --
--   entries @+ [Word "word1",Word "word2"]
--   
-- -- And if you want all entries with both: -- --
--   entries @* [Word "word1",Word "word2"]
--   
-- -- 6. Find the only the first author -- -- If an Entry has multiple authors and you want to be able to query on -- the first author, define a FirstAuthor datatype and add it to the -- result of calc. calc e=(toWords e,getFirstAuthor e) and now you can do -- -- newtype FirstAuthor = FirstAuthor Email getFirstAuthor = -- let Just (Author a)=gGet Entry in FirstAuthor a -- --
--   instance Indexable Entry ([Word],FirstAuthor)
--       ...
--       empty = ....
--                Ix (Map.empty::Map FirstAuthor (Set Entry))]
--       calcs entry = (getWords Entry,getFirstAuthor entry)
--   
--   entries @= (FirstAuthor "john@doe.com")  -- guess what this does
--   
module Happstack.Data.IxSet data IxSet a ISet :: [a] -> IxSet a IxSet :: [Ix a] -> IxSet a iSetConstr :: Constr ixSetConstr :: Constr ixSetDataType :: DataType -- | empty defines what an empty IxSet for this particular type should look -- like. calcs adds indexable values not found in the type. If you don't -- want calculated values use Indexable a (). class (Data b) => Indexable a b | a -> b empty :: (Indexable a b) => IxSet a calcs :: (Indexable a b) => a -> b -- | Function to be used for calcs in the case of an Indexable a () -- instance noCalcs :: t -> () inferIxSet :: String -> Name -> Name -> [Name] -> Q [Dec] -- | Generically traverses the argument and converts all data in it to -- Dynamic and returns all the iternal data as a list of Dynamic flatten :: (Typeable a, Data a) => a -> [Dynamic] type IndexOp = forall k a. (Ord k, Ord a) => k -> a -> Map k (Set a) -> Map k (Set a) -- | Higher order operator for modifying IxSets. Use this when your final -- function should have the form a->IxSet a->IxSet a, e.g. insert. change :: (Data a, Ord a, Data b, Indexable a b) => IndexOp -> a -> IxSet a -> IxSet a -- | Inserts an item into the IxSet insert :: (Data a, Ord a, Data b, Indexable a b) => a -> IxSet a -> IxSet a -- | Removes an item from the IxSet delete :: (Data a, Ord a, Data b, Indexable a b) => a -> IxSet a -> IxSet a -- | Will replace the item with index k. Only works if there is at most one -- item with that index in the IxSet. updateIx :: (Indexable a b, Ord a, Data a, Typeable k) => k -> a -> IxSet a -> IxSet a -- | Converts an IxSet to a Set of its elements toSet :: (Ord a) => IxSet a -> Set a -- | Takes a list of Ixs and converts it into a Set toSet' :: (Ord a) => [Ix a] -> Set a -- | Converts a Set to an IxSet fromSet :: (Indexable a b, Ord a, Data a) => Set a -> IxSet a -- | Converts a Set to an IxSet fromSet' :: (Indexable a b, Ord a, Data a) => Set a -> IxSet a -- | Converts a list to an IxSet fromList :: (Indexable a b, Ord a, Data a) => [a] -> IxSet a -- | Returns the number of unique items in the IxSet size :: (Ord a) => IxSet a -> Int -- | Converts an IxSet to its list of elements. toList :: (Ord a) => IxSet a -> [a] -- | Converts a list of Ix's toList' :: (Ord a) => [Ix a] -> [a] -- | If the IxSet is a singleton it will return the one item stored, else -- Nothing. getOne :: (Ord a) => IxSet a -> Maybe a -- | getOne with a user provided default getOneOr :: (Ord a) => a -> IxSet a -> a -- | An infix intersection operation (&&&) :: (Ord a, Data a, Indexable a b) => IxSet a -> IxSet a -> IxSet a -- | An infix union operation (|||) :: (Ord a, Data a, Indexable a b) => IxSet a -> IxSet a -> IxSet a -- | Takes the union of the two IxSets union :: (Ord a, Data a, Indexable a b) => IxSet a -> IxSet a -> IxSet a -- | Takes the intersection of the two IxSets intersection :: (Ord a, Data a, Indexable a b) => IxSet a -> IxSet a -> IxSet a -- | Infix version of getEQ (@=) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> k -> IxSet a -- | Infix version of getLT (@<) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> k -> IxSet a -- | Infix version of getGT (@>) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> k -> IxSet a -- | Infix version of getLTE (@<=) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> k -> IxSet a -- | Infix version of getGTE (@>=) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> k -> IxSet a -- | Returns the subset with indices in the open interval (k,k) (@><) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> (k, k) -> IxSet a -- | Returns the subset with indices in [k,k) (@>=<) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> (k, k) -> IxSet a -- | Returns the subset with indices in (k,k] (@><=) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> (k, k) -> IxSet a -- | Returns the subset with indices in [k,k] (@>=<=) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> (k, k) -> IxSet a -- | Creates the subset that has an index in the provided list. (@+) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> [k] -> IxSet a -- | Creates the subset that matches all the provided indices. (@*) :: (Indexable a b, Data a, Ord a, Typeable k) => IxSet a -> [k] -> IxSet a -- | Returns the subset with an index equal to the provided key. It is -- possible to provide a key of a type not indexed in the IxSet. In this -- case the function returns the empty IxSet for this type. getEQ :: (Indexable a b, Data a, Ord a, Typeable k) => k -> IxSet a -> IxSet a -- | Returns the subset with an index less than the provided key. It is -- possible to provide a key of a type not indexed in the IxSet. In this -- case the function returns the empty IxSet for this type. getLT :: (Indexable a b, Data a, Ord a, Typeable k) => k -> IxSet a -> IxSet a -- | Returns the subset with an index greater than the provided key. It is -- possible to provide a key of a type not indexed in the IxSet. In this -- case the function returns the empty IxSet for this type. getGT :: (Indexable a b, Data a, Ord a, Typeable k) => k -> IxSet a -> IxSet a -- | Returns the subset with an index less than or equal to the provided -- key. It is possible to provide a key of a type not indexed in the -- IxSet. In this case the function returns the empty IxSet for this -- type. getLTE :: (Indexable a b, Data a, Ord a, Typeable k) => k -> IxSet a -> IxSet a -- | Returns the subset with an index greater than or equal to the provided -- key. It is possible to provide a key of a type not indexed in the -- IxSet. In this case the function returns the empty IxSet for this -- type. getGTE :: (Indexable a b, Data a, Ord a, Typeable k) => k -> IxSet a -> IxSet a -- | Returns the subset with an index within the interval provided. The top -- of the interval is closed and the bottom is open. It is possible to -- provide a key of a type not indexed in the IxSet. In this case the -- function returns the empty IxSet for this type. getRange :: (Indexable a b, Typeable k, Ord a, Data a) => k -> k -> IxSet a -> IxSet a -- | Returns lists of elements paired with the indices determined by type -- inference. groupBy :: (Typeable k, Typeable t) => IxSet t -> [(k, [t])] -- | A reversed groupBy rGroupBy :: (Typeable k, Typeable t) => IxSet t -> [(k, [t])] -- | A function for building up selectors on IxSets. Used in the various -- get* functions. getOrd :: (Indexable a b, Ord a, Data a, Typeable k) => Ordering -> k -> IxSet a -> IxSet a instance [overlap ok] Typeable1 IxSet instance [overlap ok] (Data a) => Data (IxSet a) instance [overlap ok] (Show a, Indexable a b, Data a, Ord a) => Monoid (IxSet a) instance [overlap ok] (Ord a, Read a, Data a, Indexable a b) => Read (IxSet a) instance [overlap ok] (Ord a, Show a) => Show (IxSet a) instance [overlap ok] (Indexable a b, Data a, Ord a, Default a) => Default (IxSet a) instance [overlap ok] (Data ctx a, Sat (ctx (IxSet a)), Sat (ctx [a]), Indexable a b, Data a, Ord a) => Data ctx (IxSet a) instance [overlap ok] (Serialize a, Ord a, Data a, Indexable a b) => Serialize (IxSet a) instance [overlap ok] Version (IxSet a) module Happstack.Data.IxSet.Usage data Test Test :: String -> Int -> Test t2 :: Test t3 :: Test t1 :: Test c2 :: IxSet Test c3 :: IxSet Test c4 :: IxSet Test c1 :: IxSet Test s2 :: IxSet Test s3 :: IxSet Test s4 :: IxSet Test s5 :: IxSet Test s6 :: IxSet Test s7 :: IxSet Test s8 :: IxSet Test s1 :: IxSet Test instance [overlap ok] Typeable Test instance [overlap ok] Data Test instance [overlap ok] Eq Test instance [overlap ok] Ord Test instance [overlap ok] Show Test instance [overlap ok] Read Test instance [overlap ok] Indexable Test String