diff options
| author | peb <unknown> | 2005-05-09 08:25:56 +0000 |
|---|---|---|
| committer | peb <unknown> | 2005-05-09 08:25:56 +0000 |
| commit | 2b059b811db03a53e8e0f8ec1a655e507851a995 (patch) | |
| tree | 467ad9a1849bf454b22d5b2a457d09f8247041e6 /src/GF/Data | |
| parent | 01696e4f86fa156d079f2febaf103fbe229ffdb1 (diff) | |
"Committed_by_peb"
Diffstat (limited to 'src/GF/Data')
| -rw-r--r-- | src/GF/Data/Assoc.hs | 8 | ||||
| -rw-r--r-- | src/GF/Data/IncrementalDeduction.hs | 11 | ||||
| -rw-r--r-- | src/GF/Data/Utilities.hs | 22 |
3 files changed, 33 insertions, 8 deletions
diff --git a/src/GF/Data/Assoc.hs b/src/GF/Data/Assoc.hs index 64ec3bac9..f775319ea 100644 --- a/src/GF/Data/Assoc.hs +++ b/src/GF/Data/Assoc.hs @@ -5,9 +5,9 @@ -- Stability : Stable -- Portability : Haskell 98 -- --- > CVS $Date: 2005/04/12 10:49:45 $ +-- > CVS $Date: 2005/05/09 09:28:44 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.3 $ +-- > CVS $Revision: 1.4 $ -- -- Association lists, or finite maps, -- including sets as maps with result type @()@. @@ -25,6 +25,7 @@ module GF.Data.Assoc ( Assoc, aAssocs, aElems, assocMap, + assocFilter, lookupAssoc, lookupWith, (?), @@ -63,6 +64,9 @@ aElems :: Ord a => Assoc a b -> SList a -- the mapping function can take the key as information assocMap :: Ord a => (a -> b -> b') -> Assoc a b -> Assoc a b' +assocFilter :: Ord a => (b -> Bool) -> Assoc a b -> Assoc a b +assocFilter pred = listAssoc . filter (pred . snd) . aAssocs + -- | monadic lookup function, -- returning failure if the key does not exist lookupAssoc :: (Ord a, Monad m) => Assoc a b -> a -> m b diff --git a/src/GF/Data/IncrementalDeduction.hs b/src/GF/Data/IncrementalDeduction.hs index 1cf810c0e..d119610c1 100644 --- a/src/GF/Data/IncrementalDeduction.hs +++ b/src/GF/Data/IncrementalDeduction.hs @@ -4,9 +4,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/04/21 16:22:03 $ --- > CVS $Author: bringert $ --- > CVS $Revision: 1.2 $ +-- > CVS $Date: 2005/05/09 09:28:44 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.3 $ -- -- Implementation of /incremental/ deductive parsing, -- i.e. parsing one word at the time. @@ -18,7 +18,7 @@ module GF.Data.IncrementalDeduction -- * Functions chartLookup, buildChart, - chartList + chartList, chartKeys ) where import Data.Array @@ -45,6 +45,8 @@ chartList :: (Ord item, Ord key) => -- the position and the item -> [edge] +chartKeys :: (Ord item, Ord key) => IncrementalChart item key -> Int -> [key] + type IncrementalChart item key = Array Int (Assoc key (SList item)) ---------- @@ -61,4 +63,5 @@ chartList chart combine = [ combine k item | (k, state) <- assocs chart, item <- concatMap snd $ aAssocs state ] +chartKeys chart k = aElems (chart ! k) diff --git a/src/GF/Data/Utilities.hs b/src/GF/Data/Utilities.hs index 6f93add28..356bf4d1a 100644 --- a/src/GF/Data/Utilities.hs +++ b/src/GF/Data/Utilities.hs @@ -4,9 +4,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/04/11 13:52:49 $ +-- > CVS $Date: 2005/05/09 09:28:44 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.1 $ +-- > CVS $Revision: 1.2 $ -- -- Basic functions not in the standard libraries ----------------------------------------------------------------------------- @@ -14,6 +14,8 @@ module GF.Data.Utilities where +import Monad (liftM) + -- * functions on lists sameLength :: [a] -> [a] -> Bool @@ -21,6 +23,10 @@ sameLength [] [] = True sameLength (_:xs) (_:ys) = sameLength xs ys sameLength _ _ = False +notLongerThan, longerThan :: Int -> [a] -> Bool +notLongerThan n = null . snd . splitAt n +longerThan n = not . notLongerThan n + lookupList :: Eq a => a -> [(a, b)] -> [b] lookupList a [] = [] lookupList a (p:ps) | a == fst p = snd p : lookupList a ps @@ -42,6 +48,18 @@ foldMerge merge zero = fm fm [a] = a fm abs = let (as, bs) = split abs in fm as `merge` fm bs +select :: [a] -> [(a, [a])] +select [] = [] +select (x:xs) = (x,xs) : [ (y,x:ys) | (y,ys) <- select xs ] + +updateNth :: (a -> a) -> Int -> [a] -> [a] +updateNth update 0 (a : as) = update a : as +updateNth update n (a : as) = a : updateNth update (n-1) as + +updateNthM :: Monad m => (a -> m a) -> Int -> [a] -> m [a] +updateNthM update 0 (a : as) = liftM (:as) (update a) +updateNthM update n (a : as) = liftM (a:) (updateNthM update (n-1) as) + -- * functions on pairs mapFst :: (a -> a') -> (a, b) -> (a', b) |
