Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typos #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Data/Persistent/Collection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data.persistent collection
añadiendo elementos node Node (refQueue a)
implementar un query language
by key
by attribute (addAttibute)
by attribute (addAttribute)
by class
xpath
implementar un btree sobre el
Expand Down Expand Up @@ -102,7 +102,7 @@ isEmptySTM queue= do



-- | Get the reference to new or existing queue trough its name
-- | Get the reference to new or existing queue through its name
getQRef :: (Typeable a, Serialize a) => String -> RefQueue a
getQRef n = getDBRef . key $ Queue n undefined undefined

Expand Down
2 changes: 1 addition & 1 deletion Data/Persistent/IDynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tosave d@(IDyn r)= unsafePerformIO $ do

instance Serialize Save where
showp (Save s)= insertString s
readp = error "readp not impremented for Save"
readp = error "readp not implemented for Save"


errorfied :: String -> String -> a
Expand Down
34 changes: 17 additions & 17 deletions Data/TCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with read/write primitives, so the traditional syntax of Haskell STM references
can be used for interfacing with databases. As expected, the DBRefs are transactional,
because they operate in the STM monad.

A @DBRef@ is associated with its referred object trough its key.
A @DBRef@ is associated with its referred object through its key.
Since DBRefs are serializable, they can be elements of mutable cached objects themselves.
They could point to other mutable objects
and so on, so DBRefs can act as \"hardwired\" relations from mutable objects
Expand Down Expand Up @@ -136,7 +136,7 @@ DBRefs and @*Resource(s)@ primitives are completely interoperable. The latter op

-- * @IResource@ class
{- | Cached objects must be instances of `IResource`.
Such instances can be implicitly derived trough auxiliary classes for file persistence.
Such instances can be implicitly derived through auxiliary classes for file persistence.
-}
,IResource(..)

Expand Down Expand Up @@ -179,9 +179,9 @@ user `buy` item= 'withResources'[user,item] buyIt
,deleteResource

-- * Trigger operations
{- | Trriggers are called just before an object of the given type is created, modified or deleted.
{- | Triggers are called just before an object of the given type is created, modified or deleted.
The DBRef to the object and the new value is passed to the trigger.
The called trigger function has two parameters: the DBRef being accesed
The called trigger function has two parameters: the DBRef being accessed
(which still contains the old value), and the new value.
If the content of the DBRef is being deleted, the second parameter is 'Nothing'.
if the DBRef contains Nothing, then the object is being created
Expand Down Expand Up @@ -238,7 +238,7 @@ in the cache. The usual thing is that you do not have it, and the element will b
collected (but still there will be a NotRead entry for this key!!!). If the DBRef is read again, the
TCache will go to permanent storage to retrieve it.

clear opertions such `clearsyncCache` does something similar: it does not delete the
clear operations such `clearsyncCache` does something similar: it does not delete the
element from the cache. It just inform the garbage collector that there is no longer necessary to maintain
the element in the cache. So if the element has no other references (maybe you keep a
variable that point to that DBRef) it will be GCollected.
Expand Down Expand Up @@ -320,12 +320,12 @@ import Control.Exception(catch, handle, throw, evaluate, bracket, SomeException)
-- there are two references to the DBRef here
-- The Maybe one keeps it alive until the cache releases it for *Resources
-- calls which does not reference dbrefs explicitly
-- The weak reference keeps the dbref alive until is it not referenced elsewere
-- The weak reference keeps the dbref alive until is it not referenced elsewhere
data CacheElem= forall a.(IResource a,Typeable a) => CacheElem (Maybe (DBRef a)) (Weak(DBRef a))

type Ht = H.BasicHashTable String CacheElem

-- contains the hastable, last sync time
-- contains the hashtable, last sync time
type Cache = IORef (Ht , Integer)
data CheckTPVarFlags= AddToHash | NoAddToHash

Expand Down Expand Up @@ -354,7 +354,7 @@ numElems= do
return $ length elems


-- | Retuns some statistical information for the DBRefs in the cache (for debugging)
-- | Returns some statistical information for the DBRefs in the cache (for debugging)
-- This returns a tuple containing:
-- total : count of the total elements in cache
-- dirty : the elements which need to be written to the persistent storage
Expand Down Expand Up @@ -826,7 +826,7 @@ releaseTPVar cache r =do
applyTriggers [dbref] [Just r]
writeTVar tvr . Exist $ Elem r ti ti
w <- unsafeIOToSTM . mkWeakPtr dbref $ Just $ fixToCache dbref
unsafeIOToSTM $ H.insert cache keyr (CacheElem (Just dbref) w)-- accesed and modified XXX
unsafeIOToSTM $ H.insert cache keyr (CacheElem (Just dbref) w)-- accessed and modified XXX
return ()


Expand Down Expand Up @@ -862,9 +862,9 @@ updateListToHash hash kv= mapM (update1 hash) kv where
-- | Start the thread that periodically call `clearSyncCache` to clean and writes on the persistent storage.
-- it is indirectly set by means of `syncWrite`, since it is more higuer level. I recommend to use the latter
-- Otherwise, 'syncCache' or `clearSyncCache` or `atomicallySync` must be invoked explicitly or no persistence will exist.
-- Cache writes allways save a coherent state
-- Cache writes always save a coherent state
clearSyncCacheProc ::
Int -- ^ number of seconds betwen checks. objects not written to disk are written
Int -- ^ number of seconds between checks. objects not written to disk are written
-> (Integer -> Integer-> Integer-> Bool) -- ^ The user-defined check-for-cleanup-from-cache for each object. 'defaultCheck' is an example
-> Int -- ^ The max number of objects in the cache, if more, the cleanup starts
-> IO ThreadId -- ^ Identifier of the thread created
Expand All @@ -883,7 +883,7 @@ criticalSection mv f= bracket
$ const f

-- | Force the atomic write of all cached objects modified since the last save into permanent storage.
-- Cache writes allways save a coherent state. As always, only the modified objects are written.
-- Cache writes always save a coherent state. As always, only the modified objects are written.
syncCache :: IO ()
syncCache = criticalSection saving $ do
(cache,lastSync) <- readIORef refcache --`debug` "syncCache"
Expand Down Expand Up @@ -941,7 +941,7 @@ atomicallySync proc=do


-- |Saves the unsaved elems of the cache.
-- Cache writes allways save a coherent state.
-- Cache writes always save a coherent state.
-- Unlike `syncCache` this call deletes some elems from the cache when the number of elems > @sizeObjects@.
-- The deletion depends on the check criteria, expressed by the first parameter.
-- 'defaultCheck' is the one implemented to be passed by default. Look at it to understand the clearing criteria.
Expand All @@ -961,7 +961,7 @@ clearSyncCache check1 sizeObjects= criticalSection saving $ do
-- delete elems from the cache according with the checking criteria
filtercache t cache lastSync = mapM_ filter1
where
filter1 (CacheElem Nothing _)= return() --alive because the dbref is being referenced elsewere
filter1 (CacheElem Nothing _)= return() --alive because the dbref is being referenced elsewhere
filter1 (CacheElem (Just (DBRef key1 _)) w) = do
mr <- deRefWeak w
case mr of
Expand All @@ -978,15 +978,15 @@ clearSyncCache check1 sizeObjects= criticalSection saving $ do


-- | This is a default cache clearance check. It forces to drop from the cache all the
-- elems not accesed since half the time between now and the last sync
-- elems not accessed since half the time between now and the last sync
-- if it returns True, the object will be discarded from the cache
-- it is invoked when the cache size exceeds the number of objects configured
-- in 'clearSyncCacheProc' or 'clearSyncCache'
defaultCheck
:: Integer -- ^ current time in seconds
-> Integer -- ^ last access time for a given object
-> Integer -- ^ last cache synchronization (with the persisten storage)
-> Bool -- ^ return true for all the elems not accesed since half the time between now and the last sync
-> Integer -- ^ last cache synchronization (with the persistent storage)
-> Bool -- ^ return true for all the elems not accessed since half the time between now and the last sync
defaultCheck now lastAccess lastSync
| lastAccess > halftime = False
| otherwise = True
Expand Down
2 changes: 1 addition & 1 deletion Data/TCache/Defs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Example:
data Car= Car{owner :: DBRef Person , cname:: String} deriving (Show, Read, Eq, Typeable)
@

Since Person and Car are instances of 'Read' ans 'Show', by defining the 'Indexable' instance
Since Person and Car are instances of 'Read' and 'Show', by defining the 'Indexable' instance
will implicitly define the IResource instance for file persistence:

@
Expand Down
10 changes: 5 additions & 5 deletions Data/TCache/IResource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module Data.TCache.IResource where
-}
class IResource a where
{- The `keyResource string must be a unique since this is used to index it in the hash table.
when accessing a resource, the user must provide a partial object for wich the key can be obtained.
when accessing a resource, the user must provide a partial object for which the key can be obtained.
for example:

@data Person= Person{name, surname:: String, account :: Int ....)

keyResource Person n s ...= n++s@

the data being accesed must define the fields used by keyResource. For example
the data being accessed must define the fields used by keyResource. For example

@ readResource Person {name="John", surname= "Adams"}@

Expand All @@ -27,8 +27,8 @@ class IResource a where

{- | Implements the database access and marshalling of the object.
while the database access must be strict, the marshaling must be lazy if, as is often the case,
some parts of the object are not really accesed.
If the object contains DBRefs, this avoids unnecesary cache lookups.
some parts of the object are not really accessed.
If the object contains DBRefs, this avoids unnecessary cache lookups.
This method is called within 'atomically' blocks.
Since STM transactions retry, readResourceByKey may be called twice in strange situations. So it must be idempotent, not only in the result but also in the effect in the database
. However, because it is executed by 'safeIOToSTM' it is guaranteed that the execution is not interrupted.
Expand Down Expand Up @@ -60,7 +60,7 @@ class IResource a where
writeResources :: [a] -> IO()
writeResources= mapM_ writeResource

-- | Delete the resource. It is called syncronously. So it must commit
-- | Delete the resource. It is called synchronously. So it must commit
delResource:: a-> IO()
delResource x= delResources [x]

Expand Down
6 changes: 3 additions & 3 deletions Data/TCache/IndexQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it includes

- a 'recordsWith' clause to extract entire registers

An example that register the owner and name fields fo the Car register and the
An example that register the owner and name fields of the Car register and the
name of the Person register, create the Bruce register, return the Bruce DBRef, create two Car registers with bruce as owner
and query for the registers with bruce as owner and its name alpabeticaly higuer than \"Bat mobile\"

Expand Down Expand Up @@ -234,7 +234,7 @@ class RelationOps field1 field2 res | field1 field2 -> res where
(.<=.) :: field1 -> field2 -> STM res
(.<.) :: field1 -> field2 -> STM res

-- Instance of relations betweeen fields and values
-- Instance of relations between fields and values
-- field .op. value
instance (Queriable reg a) => RelationOps (reg -> a) a [DBRef reg] where
(.==.) field value= do
Expand All @@ -261,7 +261,7 @@ join op field1 field2 =do

type JoinData reg reg'=[([DBRef reg],[DBRef reg'])]

-- Instance of relations betweeen fields
-- Instance of relations between fields
-- field1 .op. field2
instance (Queriable reg a ,Queriable reg' a ) =>RelationOps (reg -> a) (reg' -> a) (JoinData reg reg') where

Expand Down
2 changes: 1 addition & 1 deletion Data/TCache/IndexText.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ indexText sel convert= do
indexList
:: (IResource a, Typeable a, Typeable b)
=> (a -> b) -- ^ field to index
-> (b -> [T.Text]) -- ^ method to convert a field element to Text (for example `pack . show` in case of elemets with Show instances)
-> (b -> [T.Text]) -- ^ method to convert a field element to Text (for example `pack . show` in case of elements with Show instances)
-> IO ()
indexList sel convert= do
addTrigger (indext sel convert)
Expand Down
2 changes: 1 addition & 1 deletion Data/TCache/Memoization.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data Cached a b= forall m.Executable m => Cached a (a -> m b) b Integer deriving
context = unsafePerformIO newContext

-- | given a string, return a key that can be used in Indexable instances
-- Of non persistent objects, such are cached objects (it changes fron execution to execution)
-- Of non persistent objects, such are cached objects (it changes from execution to execution)
-- . It uses `addrHash`
addrStr :: a -> String
addrStr x= "addr" ++ show hash
Expand Down
4 changes: 2 additions & 2 deletions Data/TCache/Triggers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ cmtriggers = unsafePerformIO $ newIORef []


{- | Add an user defined trigger to the list of triggers
Trriggers are called just before an object of the given type is created, modified or deleted.
Triggers are called just before an object of the given type is created, modified or deleted.
The DBRef to the object and the new value is passed to the trigger.
The called trigger function has two parameters: the DBRef being accesed
The called trigger function has two parameters: the DBRef being accessed
(which still contains the old value), and the new value.
If the DBRef is being deleted, the second parameter is 'Nothing'.
if the DBRef contains Nothing, then the object is being created
Expand Down
4 changes: 2 additions & 2 deletions demos/DBRef.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ main = do

let myCompanyRef2 = read $ show myCompanyRef :: DBRef Company
putMsg "DBRefs are identified by the key of the referenced object"
putMsg "DBRef's are alse instances of read"
putMsg "DBRef's are also instances of read"

print myCompanyRef2
putMsg "DBReference's with the same key point to the same data object"
Expand All @@ -114,7 +114,7 @@ main = do

putMsg "Before salary increase, the company personnel is accessed with the second reference"
printSalaries myCompanyRef2
putMsg "atomically increase the salaries of all the personel"
putMsg "atomically increase the salaries of all the personnel"
atomically $ increaseSalaries 10
putMsg "after the increase"
printSalaries myCompanyRef2
Expand Down
4 changes: 2 additions & 2 deletions demos/caching.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ main = do
putStrLn ""
putStrLn "This program tests the caching, cleaning, re-retrieval and updating of the cache."
putStrLn "It uses the DefaultPersistence (disk) and defaultCheck (cleaning rules)."
putStrLn "It writes asyncronously every 10 seconds all changed elemements to disk."
putStrLn "It writes asynchronously every 10 seconds all changed elements to disk."
putStrLn "When there is more than the allowed number of elements (100) in the cache it cleans them by the given rule."
putStrLn "With defaultCheck it drops elements which where not accesed since half the time between now and the last sync."
putStrLn "With defaultCheck it drops elements which where not accessed since half the time between now and the last sync."

putStrLn ""
putStrLn "Creating 200 resources with content: n 0"
Expand Down
2 changes: 1 addition & 1 deletion demos/triggerRelational.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ So a better version of addCar is:
> Nothing -> return True
> Just Car{owner= pother} ->
> if pother== powner
> then return False -- is unchanged, not necesary to update
> then return False -- is unchanged, not necessary to update
> else do
> deleteOwner pother pcar
> return True
Expand Down