Commit 13b7f0a1 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

wta: Fix hlint warnings

parent 1f8b6e79
...@@ -29,13 +29,13 @@ runGenerator config action = runReaderT action config ...@@ -29,13 +29,13 @@ runGenerator config action = runReaderT action config
genMonoidValue :: Generator m m genMonoidValue :: Generator m m
genMonoidValue = asks ((monoid . spec) &&& differentValues) >>= \case genMonoidValue = asks ((monoid . spec) &&& differentValues) >>= \case
(Powerset, Nothing) -> liftIO $ randomIO (Powerset, Nothing) -> liftIO randomIO
(Powerset, Just 1) -> return True (Powerset, Just 1) -> return True
(Powerset, Just 2) -> liftIO $ randomIO (Powerset, Just 2) -> liftIO randomIO
(Powerset, _) -> error $ "differentValues >2 not supported for powerset" (Powerset, _) -> error "differentValues >2 not supported for powerset"
(OrWord, Nothing) -> liftIO $ randomIO (OrWord, Nothing) -> liftIO randomIO
(OrWord, Just x) -> liftIO $ randomRIO (1, fromIntegral x) (OrWord, Just x) -> liftIO $ randomRIO (1, fromIntegral x)
(MaxInt, Nothing) -> liftIO $ randomIO (MaxInt, Nothing) -> liftIO randomIO
(MaxInt, Just x) -> liftIO $ randomRIO (1, x) (MaxInt, Just x) -> liftIO $ randomRIO (1, x)
genStates :: Generator m (Vector m) genStates :: Generator m (Vector m)
...@@ -49,8 +49,7 @@ aritySummand arity = do ...@@ -49,8 +49,7 @@ aritySummand arity = do
return $ V.length (V.filter (/= 0) (V.take arity arities)) return $ V.length (V.filter (/= 0) (V.take arity arities))
decideZero :: Generator m Bool decideZero :: Generator m Bool
decideZero = do decideZero = asks zeroFreq >>= liftIO . decide
asks zeroFreq >>= liftIO . decide
-- Generates Nothing, when it decides that a zero value would be in order -- Generates Nothing, when it decides that a zero value would be in order
genTransition :: Int -> Int -> [State] -> Generator m (Maybe (Transition m)) genTransition :: Int -> Int -> [State] -> Generator m (Maybe (Transition m))
...@@ -67,7 +66,7 @@ genTransition arity symbol succs = decideZero >>= \case ...@@ -67,7 +66,7 @@ genTransition arity symbol succs = decideZero >>= \case
genForSymbol :: Int -> Int -> Generator m (Vector (Transition m)) genForSymbol :: Int -> Int -> Generator m (Vector (Transition m))
genForSymbol arity symbol = do genForSymbol arity symbol = do
states <- asks (numStates . spec) states <- asks (numStates . spec)
fmap (V.fromList . catMaybes) $ traverse V.fromList . catMaybes <$> traverse
(genTransition arity symbol) (genTransition arity symbol)
(replicateM arity (coerce [0 .. states - 1])) (replicateM arity (coerce [0 .. states - 1]))
...@@ -79,7 +78,7 @@ genForArity arity = do ...@@ -79,7 +78,7 @@ genForArity arity = do
genStateTransitions :: Generator m (Vector (Transition m)) genStateTransitions :: Generator m (Vector (Transition m))
genStateTransitions = do genStateTransitions = do
arities <- asks (numSymbols . spec) arities <- asks (numSymbols . spec)
fold <$> (traverse genForArity (V.findIndices (/= 0) arities)) fold <$> traverse genForArity (V.findIndices (/= 0) arities)
genTransitions :: Generator m (Vector (Vector (Transition m))) genTransitions :: Generator m (Vector (Vector (Transition m)))
genTransitions = do genTransitions = do
......
{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-} {-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ExistentialQuantification #-}
...@@ -58,7 +57,7 @@ readSymbols :: Options.ReadM SymbolSpec ...@@ -58,7 +57,7 @@ readSymbols :: Options.ReadM SymbolSpec
readSymbols = Options.maybeReader (Mega.parseMaybe parser) readSymbols = Options.maybeReader (Mega.parseMaybe parser)
where where
parser :: Mega.Parsec Void String (Vector Int) parser :: Mega.Parsec Void String (Vector Int)
parser = V.fromList <$> Mega.decimal `Mega.sepBy` (Mega.string ",") parser = V.fromList <$> Mega.decimal `Mega.sepBy` Mega.string ","
readCount :: String -> Either String Int readCount :: String -> Either String Int
readCount input = case readDec input of readCount input = case readDec input of
...@@ -128,7 +127,7 @@ computeProbability spec (OutDegree d) = ...@@ -128,7 +127,7 @@ computeProbability spec (OutDegree d) =
main :: IO () main :: IO ()
main = do main = do
let optSpec = let optSpec =
Options.info (parseOpts Options.<**> Options.helper) (Options.fullDesc) Options.info (parseOpts Options.<**> Options.helper) Options.fullDesc
opts <- Options.execParser optSpec opts <- Options.execParser optSpec
case optMonoid opts of case optMonoid opts of
...@@ -138,9 +137,7 @@ main = do ...@@ -138,9 +137,7 @@ main = do
exitFailure exitFailure
_ -> return () _ -> return ()
case optRandomState opts of mapM_ setStdGen (optRandomState opts)
Nothing -> return ()
Just x -> setStdGen x
withSpec opts $ \spec -> do withSpec opts $ \spec -> do
randGen <- getStdGen randGen <- getStdGen
......
...@@ -14,12 +14,12 @@ import Data.Maybe ...@@ -14,12 +14,12 @@ import Data.Maybe
import Types import Types
wtaFunctor :: (WTASpec m) -> Builder wtaFunctor :: WTASpec m -> Builder
wtaFunctor wta = monoidForStates (monoid wta) <> " × " <> withMonoidForWeights wtaFunctor wta = monoidForStates (monoid wta) <> " × " <> withMonoidForWeights
(monoid wta) (monoid wta)
(polynomial (numSymbols wta)) (polynomial (numSymbols wta))
monoidForStates :: (MonoidType m) -> Builder monoidForStates :: MonoidType m -> Builder
monoidForStates MaxInt = "Z" monoidForStates MaxInt = "Z"
monoidForStates OrWord = "N" monoidForStates OrWord = "N"
monoidForStates Powerset = "2" monoidForStates Powerset = "2"
...@@ -44,9 +44,7 @@ buildValue :: ValueUse -> MonoidType m -> m -> Builder ...@@ -44,9 +44,7 @@ buildValue :: ValueUse -> MonoidType m -> m -> Builder
buildValue _ MaxInt i = Build.decimal i buildValue _ MaxInt i = Build.decimal i
buildValue Weight OrWord w = "0x" <> Build.hexadecimal w buildValue Weight OrWord w = "0x" <> Build.hexadecimal w
buildValue StateVal OrWord w = Build.decimal w buildValue StateVal OrWord w = Build.decimal w
buildValue _ Powerset b = case b of buildValue _ Powerset b = if b then "1" else "0"
False -> "0"
True -> "1"
buildTransition :: MonoidType m -> Transition m -> Builder buildTransition :: MonoidType m -> Transition m -> Builder
buildTransition mon trans = buildTransition mon trans =
...@@ -59,7 +57,7 @@ buildTransition mon trans = ...@@ -59,7 +57,7 @@ buildTransition mon trans =
where where
buildSuccs succs = if V.null succs buildSuccs succs = if V.null succs
then Build.decimal (symbol trans) then Build.decimal (symbol trans)
else "(" <> Build.decimal (symbol trans) <> ", " <> (sepList ", " buildStateName (successors trans)) <> ")" else "(" <> Build.decimal (symbol trans) <> ", " <> sepList ", " buildStateName (successors trans) <> ")"
buildWeight :: MonoidType m -> m -> Builder buildWeight :: MonoidType m -> m -> Builder
buildWeight Powerset _ = "" buildWeight Powerset _ = ""
...@@ -88,7 +86,7 @@ buildStates wta = foldMap ...@@ -88,7 +86,7 @@ buildStates wta = foldMap
where indices = [0 .. V.length (stateValue wta) - 1] where indices = [0 .. V.length (stateValue wta) - 1]
buildWTA :: WTA m -> Builder buildWTA :: WTA m -> Builder
buildWTA a = (wtaFunctor (spec a)) <> "\n" <> buildStates a buildWTA a = wtaFunctor (spec a) <> "\n" <> buildStates a
-- helpers -- helpers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment