Commit e7905578 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

wta: Allow --different-values for powerset

Even if it only allows a range of [1,2], it's there for completeness and makes
the benchmark script a bit easier.
parent 719c0a4d
...@@ -30,7 +30,9 @@ runGenerator config action = runReaderT action config ...@@ -30,7 +30,9 @@ 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, _) -> error $ "differentValues not supported for powerset" -- FIXME detect this early (and handle the case <=2) (Powerset, Just 1) -> return True
(Powerset, Just 2) -> liftIO $ randomIO
(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
......
...@@ -17,6 +17,8 @@ import qualified Text.Megaparsec.Char.Lexer as Mega ...@@ -17,6 +17,8 @@ import qualified Text.Megaparsec.Char.Lexer as Mega
import Data.Void import Data.Void
import System.Random import System.Random
import Numeric import Numeric
import System.IO
import System.Exit
import Types import Types
import Generator import Generator
...@@ -115,6 +117,13 @@ main = do ...@@ -115,6 +117,13 @@ main = do
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
SomeMonoid Powerset
| maybe False (>2) (optDifferentValues opts) -> do
hPutStrLn stderr "error: Powerset can't have more than 2 different values"
exitFailure
_ -> return ()
case optRandomState opts of case optRandomState opts of
Nothing -> return () Nothing -> return ()
Just x -> setStdGen x Just x -> setStdGen x
......
...@@ -19,7 +19,6 @@ data MonoidType m where ...@@ -19,7 +19,6 @@ data MonoidType m where
OrWord ::MonoidType Word OrWord ::MonoidType Word
Powerset ::MonoidType Bool Powerset ::MonoidType Bool
-- | For each arity, the number of symbols -- | For each arity, the number of symbols
type SymbolSpec = Vector Int type SymbolSpec = Vector Int
......
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