{-# LANGUAGE CPP #-}
module Z3.Opts
(
Opts
, setOpts
, stdOpts
, (+?)
, opt
, OptValue
)
where
import qualified Z3.Base as Base
import Data.Fixed ( Fixed )
import qualified Data.Fixed as Fixed
import Data.Monoid ( Monoid(..) )
#if MIN_VERSION_base(4,9,0)
import Data.Semigroup ( Semigroup (..) )
#endif
newtype Opts = Opts [Opt]
#if MIN_VERSION_base(4,9,0)
instance Semigroup Opts where
Opts ps1 :: [Opt]
ps1 <> :: Opts -> Opts -> Opts
<> Opts ps2 :: [Opt]
ps2 = [Opt] -> Opts
Opts ([Opt]
ps1 [Opt] -> [Opt] -> [Opt]
forall a. [a] -> [a] -> [a]
++ [Opt]
ps2)
#endif
instance Monoid Opts where
mempty :: Opts
mempty = [Opt] -> Opts
Opts []
#if MIN_VERSION_base(4,9,0)
mappend :: Opts -> Opts -> Opts
mappend = Opts -> Opts -> Opts
forall a. Semigroup a => a -> a -> a
(<>)
#else
Opts ps1 `mappend` Opts ps2 = Opts (ps1 ++ ps2)
#endif
singleton :: Opt -> Opts
singleton :: Opt -> Opts
singleton o :: Opt
o = [Opt] -> Opts
Opts [Opt
o]
stdOpts :: Opts
stdOpts :: Opts
stdOpts = Opts
forall a. Monoid a => a
mempty
(+?) :: Opts -> Opts -> Opts
+? :: Opts -> Opts -> Opts
(+?) = Opts -> Opts -> Opts
forall a. Monoid a => a -> a -> a
mappend
opt :: OptValue val => String -> val -> Opts
opt :: String -> val -> Opts
opt oid :: String
oid val :: val
val = Opt -> Opts
singleton (Opt -> Opts) -> Opt -> Opts
forall a b. (a -> b) -> a -> b
$ String -> val -> Opt
forall val. OptValue val => String -> val -> Opt
option String
oid val
val
setOpts :: Base.Config -> Opts -> IO ()
setOpts :: Config -> Opts -> IO ()
setOpts baseCfg :: Config
baseCfg (Opts params :: [Opt]
params) = (Opt -> IO ()) -> [Opt] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Config -> Opt -> IO ()
setOpt Config
baseCfg) [Opt]
params
data Opt = Opt String
String
setOpt :: Base.Config -> Opt -> IO ()
setOpt :: Config -> Opt -> IO ()
setOpt baseCfg :: Config
baseCfg (Opt oid :: String
oid val :: String
val) = Config -> String -> String -> IO ()
Base.setParamValue Config
baseCfg String
oid String
val
class OptValue val where
option :: String -> val -> Opt
instance OptValue Bool where
option :: String -> Bool -> Opt
option oid :: String
oid = String -> String -> Opt
Opt String
oid (String -> Opt) -> (Bool -> String) -> Bool -> Opt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> String
boolVal
instance OptValue Int where
option :: String -> Int -> Opt
option oid :: String
oid = String -> String -> Opt
Opt String
oid (String -> Opt) -> (Int -> String) -> Int -> Opt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show
instance OptValue Integer where
option :: String -> Integer -> Opt
option oid :: String
oid = String -> String -> Opt
Opt String
oid (String -> Opt) -> (Integer -> String) -> Integer -> Opt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show
instance Fixed.HasResolution a => OptValue (Fixed a) where
option :: String -> Fixed a -> Opt
option oid :: String
oid = String -> String -> Opt
Opt String
oid (String -> Opt) -> (Fixed a -> String) -> Fixed a -> Opt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Fixed a -> String
forall a. HasResolution a => Bool -> Fixed a -> String
Fixed.showFixed Bool
True
instance OptValue [Char] where
option :: String -> String -> Opt
option = String -> String -> Opt
Opt
boolVal :: Bool -> String
boolVal :: Bool -> String
boolVal True = "true"
boolVal False = "false"