Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. distinctG :: (Ord a, Show a) => a -> (a -> Bool) -> [a] -> Logger (Maybe [a])
  2. distinctG y p as = evalStateT (fun as) Set.empty where
  3.   fun []     = do { pure $ pure [] }
  4.   fun (x:xs) = do
  5.     set <- getT
  6.     if x > y
  7.     then StateT $ \s -> Logger ("fail: " ++ show x) (Nothing, s)
  8.     else do
  9.       set <- getT
  10.       if (x `Set.notMember` set)
  11.       then do
  12.         putT (Set.insert x set)
  13.         case evalStateT (fun xs) set of
  14.           Logger e Nothing -> do
  15.             if p x
  16.             then StateT $ \s -> Logger ("satisfy " ++ show x ++ ";" ++ e) (Nothing, s)
  17.             else StateT $ \s -> Logger e (Nothing, s)
  18.           Logger e (Just rs) -> do
  19.             if p x
  20.             then StateT $ \s -> Logger ("satisfy " ++ show x ++ ";" ++ e) (Just (x : rs), s)
  21.             else StateT $ \s -> Logger e (Just (x : rs), s)
  22.       else do
  23.         case evalStateT (fun xs) set of
  24.           Logger e Nothing -> StateT $ \s -> Logger e (Nothing, s)
  25.           Logger e (Just rs) -> StateT $ \s -> Logger e (Just rs, s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement