summaryrefslogtreecommitdiff
path: root/src/GF/Data
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2005-11-17 23:17:42 +0000
committeraarne <aarne@cs.chalmers.se>2005-11-17 23:17:42 +0000
commit524c4829f9cc5720c18b8d43bd430d0627edcb89 (patch)
treec10cc4dbb4b6f0bb5464369b1ed3d028c29fec18 /src/GF/Data
parente29a1430bf76b00c3714b72b7763190df6716081 (diff)
nondeterministic lexer, e.g. subseqs
Diffstat (limited to 'src/GF/Data')
-rw-r--r--src/GF/Data/Operations.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/GF/Data/Operations.hs b/src/GF/Data/Operations.hs
index 339a053cf..f5434486f 100644
--- a/src/GF/Data/Operations.hs
+++ b/src/GF/Data/Operations.hs
@@ -65,14 +65,14 @@ module GF.Data.Operations (-- * misc functions
updateAssoc, removeAssoc,
-- * chop into separator-separated parts
- chunks, readIntArg,
+ chunks, readIntArg, subSequences,
-- * state monad with error; from Agda 6\/11\/2001
STM(..), appSTM, stm, stmr, readSTM, updateSTM, writeSTM, done,
-- * error monad class
- ErrorMonad(..), checkAgain, checks, allChecks
-
+ ErrorMonad(..), checkAgain, checks, allChecks, doUntil
+
) where
import Data.Char (isSpace, toUpper, isSpace, isDigit)
@@ -656,3 +656,16 @@ allChecks ms = case ms of
(m: ms) -> let rs = allChecks ms in handle_ (liftM2 (:) m rs) rs
_ -> return []
+doUntil :: ErrorMonad m => (a -> Bool) -> [m a] -> m a
+doUntil cond ms = case ms of
+ a:as -> do
+ v <- a
+ if cond v then return v else doUntil cond as
+ _ -> raise "no result"
+
+-- subsequences sorted from longest to shortest ; their number is 2^n
+subSequences :: [a] -> [[a]]
+subSequences = sortBy (\x y -> compare (length y) (length x)) . subs where
+ subs xs = case xs of
+ [] -> [[]]
+ x:xs -> let xss = subs xs in [x:y | y <- xss] ++ xss