diff options
| author | aarne <aarne@cs.chalmers.se> | 2005-11-17 23:17:42 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2005-11-17 23:17:42 +0000 |
| commit | 524c4829f9cc5720c18b8d43bd430d0627edcb89 (patch) | |
| tree | c10cc4dbb4b6f0bb5464369b1ed3d028c29fec18 /src/GF/Data/Operations.hs | |
| parent | e29a1430bf76b00c3714b72b7763190df6716081 (diff) | |
nondeterministic lexer, e.g. subseqs
Diffstat (limited to 'src/GF/Data/Operations.hs')
| -rw-r--r-- | src/GF/Data/Operations.hs | 19 |
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 |
