1module Main where23import Conduit4import qualified SimpleSMT as SMT5import Data.Text (unpack, Text)67average :: Monad m => ConduitT Int Void m Int8average =9 getZipSink (go <$> ZipSink sumC <*> ZipSink lengthC)10 where11 go :: Int -> Int -> Int12 go total len = total `div` fromIntegral len1314countDepth :: SMT.SExpr -> Int15countDepth (SMT.Atom _) = 016countDepth (SMT.List []) = 117countDepth (SMT.List lst) = 1 + (maximum $ map countDepth lst)1819yieldSExpr :: ConduitM Text SMT.SExpr IO ()20yieldSExpr = loop ""21 where22 loop rest = await >>= maybe (return ()) (go . (rest ++) . unpack)23 go x =24 case SMT.readSExpr x of25 Just (expr, rest) -> yield expr >> go rest26 Nothing -> loop x2728maxDepth :: IO Int29maxDepth =30 runConduit31 $ stdinC32 .| decodeUtf8C33 .| yieldSExpr34 .| mapC countDepth35 .| average3637main :: IO ()38main = maxDepth >>= print