Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- distinctG :: (Ord a, Show a) => a -> (a -> Bool) -> [a] -> Logger (Maybe [a])
- distinctG y p as = evalStateT (fun as) Set.empty where
- fun [] = do { pure $ pure [] }
- fun (x:xs) = do
- set <- getT
- if x > y
- then StateT $ \s -> Logger ("fail: " ++ show x) (Nothing, s)
- else do
- set <- getT
- if (x `Set.notMember` set)
- then do
- putT (Set.insert x set)
- case evalStateT (fun xs) set of
- Logger e Nothing -> do
- if p x
- then StateT $ \s -> Logger ("satisfy " ++ show x ++ ";" ++ e) (Nothing, s)
- else StateT $ \s -> Logger e (Nothing, s)
- Logger e (Just rs) -> do
- if p x
- then StateT $ \s -> Logger ("satisfy " ++ show x ++ ";" ++ e) (Just (x : rs), s)
- else StateT $ \s -> Logger e (Just (x : rs), s)
- else do
- case evalStateT (fun xs) set of
- Logger e Nothing -> StateT $ \s -> Logger e (Nothing, s)
- Logger e (Just rs) -> StateT $ \s -> Logger e (Just rs, s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement