summaryrefslogtreecommitdiff
path: root/src/GF/Data
diff options
context:
space:
mode:
authorpeb <unknown>2005-03-29 10:17:53 +0000
committerpeb <unknown>2005-03-29 10:17:53 +0000
commit67aa6e7a81d8d22ff8409ed59fab7bacde2312a6 (patch)
tree1759bd8e1b314e2b98ffb0a6116e2a1fb515908d /src/GF/Data
parentccf6017b030fcefd5964979f1b6d55e722616ef7 (diff)
"Committed_by_peb"
Diffstat (limited to 'src/GF/Data')
-rw-r--r--src/GF/Data/Assoc.hs36
-rw-r--r--src/GF/Data/BacktrackM.hs6
-rw-r--r--src/GF/Data/Operations.hs13
3 files changed, 31 insertions, 24 deletions
diff --git a/src/GF/Data/Assoc.hs b/src/GF/Data/Assoc.hs
index 261fdb980..c783ef744 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/03/21 14:17:39 $
+-- > CVS $Date: 2005/03/29 11:17:54 $
-- > CVS $Author: peb $
--- > CVS $Revision: 1.1 $
+-- > CVS $Revision: 1.2 $
--
-- Association lists, or finite maps,
-- including sets as maps with result type @()@.
@@ -16,18 +16,20 @@
-----------------------------------------------------------------------------
module GF.Data.Assoc ( Assoc,
- Set,
- listAssoc,
- listSet,
- accumAssoc,
- aAssocs,
- aElems,
- assocMap,
- lookupAssoc,
- lookupWith,
- (?),
- (?=)
- ) where
+ Set,
+ emptyAssoc,
+ emptySet,
+ listAssoc,
+ listSet,
+ accumAssoc,
+ aAssocs,
+ aElems,
+ assocMap,
+ lookupAssoc,
+ lookupWith,
+ (?),
+ (?=)
+ ) where
import GF.Data.SortedList
@@ -36,6 +38,9 @@ infixl 9 ?, ?=
-- | a set is a finite map with empty values
type Set a = Assoc a ()
+emptyAssoc :: Ord a => Assoc a b
+emptySet :: Ord a => Set a
+
-- | creating a finite map from a sorted key-value list
listAssoc :: Ord a => SList (a, b) -> Assoc a b
@@ -78,6 +83,9 @@ lookupWith :: Ord a => b -> Assoc a b -> a -> b
data Assoc a b = ANil | ANode (Assoc a b) a b (Assoc a b)
deriving (Eq, Show)
+emptyAssoc = ANil
+emptySet = emptyAssoc
+
listAssoc as = assoc
where (assoc, []) = sl2bst (length as) as
sl2bst 0 xs = (ANil, xs)
diff --git a/src/GF/Data/BacktrackM.hs b/src/GF/Data/BacktrackM.hs
index 5abc9863d..555f5fec1 100644
--- a/src/GF/Data/BacktrackM.hs
+++ b/src/GF/Data/BacktrackM.hs
@@ -5,11 +5,11 @@
-- Stability : (stable)
-- Portability : (portable)
--
--- > CVS $Date: 2005/03/21 14:17:39 $
+-- > CVS $Date: 2005/03/29 11:17:54 $
-- > CVS $Author: peb $
--- > CVS $Revision: 1.1 $
+-- > CVS $Revision: 1.2 $
--
--- Backtracking state monad, with r/o environment
+-- Backtracking state monad, with r\/o environment
-----------------------------------------------------------------------------
diff --git a/src/GF/Data/Operations.hs b/src/GF/Data/Operations.hs
index 551b0f1aa..3f5600f93 100644
--- a/src/GF/Data/Operations.hs
+++ b/src/GF/Data/Operations.hs
@@ -5,9 +5,9 @@
-- Stability : (stable)
-- Portability : (portable)
--
--- > CVS $Date: 2005/03/14 23:45:36 $
--- > CVS $Author: krijo $
--- > CVS $Revision: 1.17 $
+-- > CVS $Date: 2005/03/29 11:17:56 $
+-- > CVS $Author: peb $
+-- > CVS $Revision: 1.18 $
--
-- some auxiliary GF operations. AR 19\/6\/1998 -- 6\/2\/2001
--
@@ -56,7 +56,7 @@ module Operations (-- * misc functions
sortByLongest, combinations, mkTextFile, initFilePath,
-- * topological sorting with test of cyclicity
- topoTest, topoSort,
+ topoTest, topoSort, cyclesIn,
-- * the generic fix point iterator
iterFix,
@@ -570,8 +570,7 @@ mkTextFile name = do
initFilePath :: FilePath -> FilePath
initFilePath f = reverse (dropWhile (/='/') (reverse f))
--- topological sorting with test of cyclicity
-
+-- | topological sorting with test of cyclicity
topoTest :: Eq a => [(a,[a])] -> Either [a] [[a]]
topoTest g = if length g' == length g then Left g' else Right (cyclesIn g ++[[]])
where
@@ -591,7 +590,7 @@ cyclesIn deps = nubb $ clean $ filt $ iterFix findDep immediate where
remdup [] = []
-
+-- | topological sorting
topoSort :: Eq a => [(a,[a])] -> [a]
topoSort g = reverse $ tsort 0 [ffs | ffs@(f,_) <- g, inDeg f == 0] [] where
tsort _ [] r = r