-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Language to express rules for Nomic -- -- Provide a DSL to express rules for a Nomic game, with evaluation -- engine. See package Nomyx for a full game implementation. @package Nomyx-Language @version 0.2.3 module Paths_Nomyx_Language version :: Version getBinDir :: IO FilePath getLibDir :: IO FilePath getDataDir :: IO FilePath getLibexecDir :: IO FilePath getDataFileName :: FilePath -> IO FilePath module Language.Nomyx.Utils -- | durations oneWeek :: NominalDiffTime -- | durations oneMinute :: NominalDiffTime -- | durations oneHour :: NominalDiffTime -- | durations oneDay :: NominalDiffTime -- | an equality that tests also the types. (===) :: (Typeable a, Typeable b, Eq b) => a -> b -> Bool -- | Replaces all instances of a value in a list by another value. replaceWith :: (a -> Bool) -> a -> [a] -> [a] tracePN :: Monad m => Int -> String -> m () traceData :: Show a => String -> a -> a mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] parse822Time :: String -> UTCTime sndMaybe :: (a, Maybe b) -> Maybe (a, b) mapStateIO :: Show s => State s a -> StateT s IO a getFreeNumber :: (Eq a, Num a, Enum a) => [a] -> a -- | This module containt the type definitions necessary to build a Nomic -- rule. module Language.Nomyx.Expression type PlayerNumber = Int type PlayerName = String type RuleNumber = Int type RuleName = String type RuleDesc = String type RuleText = String type RuleCode = String type EventNumber = Int type EventName = String type VarName = String type GameName = String type Code = String -- | A Nomex (Nomyx Expression) allows the players to write rules. | within -- the rules, you can access and modify the state of the game. | It is a -- compositional algebra defined with a GADT. data Nomex a NewVar :: VarName -> a -> Nomex (Maybe (V a)) ReadVar :: (V a) -> Nomex (Maybe a) WriteVar :: (V a) -> a -> Nomex Bool DelVar :: (V a) -> Nomex Bool OnEvent :: Event e -> ((EventNumber, EventData e) -> Nomex ()) -> Nomex EventNumber DelEvent :: EventNumber -> Nomex Bool DelAllEvents :: Event e -> Nomex () SendMessage :: Event (Message a) -> a -> Nomex () ProposeRule :: Rule -> Nomex Bool ActivateRule :: RuleNumber -> Nomex Bool RejectRule :: RuleNumber -> Nomex Bool AddRule :: Rule -> Nomex Bool DelRule :: RuleNumber -> Nomex Bool ModifyRule :: RuleNumber -> Rule -> Nomex Bool GetRules :: Nomex [Rule] GetPlayers :: Nomex [PlayerInfo] SetPlayerName :: PlayerNumber -> PlayerName -> Nomex Bool DelPlayer :: PlayerNumber -> Nomex Bool SetVictory :: [PlayerNumber] -> Nomex () Output :: PlayerNumber -> String -> Nomex () CurrentTime :: Nomex UTCTime SelfRuleNumber :: Nomex RuleNumber Return :: a -> Nomex a Bind :: Nomex a -> (a -> Nomex b) -> Nomex b ThrowError :: String -> Nomex a CatchError :: Nomex a -> (String -> Nomex a) -> Nomex a -- | a container for a variable name and type data V a V :: String -> V a varName :: V a -> String -- | stores the variable's data data Var Var :: Int -> String -> a -> Var _vRuleNumber :: Var -> Int _vName :: Var -> String vData :: Var -> a type Output = (PlayerNumber, String) type Id a = a -- | events types data Player Arrive :: Player Leave :: Player data RuleEvent Proposed :: RuleEvent Activated :: RuleEvent Rejected :: RuleEvent Added :: RuleEvent Modified :: RuleEvent Deleted :: RuleEvent data Time data EvRule data Message m data InputChoice c data InputString data Victory -- | events names data Event a Player :: Player -> Event Player RuleEv :: RuleEvent -> Event RuleEvent Time :: UTCTime -> Event Time Message :: String -> Event (Message m) InputChoice :: PlayerNumber -> String -> [c] -> c -> Event (InputChoice c) InputString :: PlayerNumber -> String -> Event InputString Victory :: Event Victory -- | data associated with each events data EventData a PlayerData :: PlayerInfo -> EventData Player playerData :: EventData Player -> PlayerInfo RuleData :: Rule -> EventData RuleEvent ruleData :: EventData RuleEvent -> Rule TimeData :: UTCTime -> EventData Time timeData :: EventData Time -> UTCTime MessageData :: m -> EventData (Message m) messageData :: EventData (Message m) -> m InputChoiceData :: c -> EventData (InputChoice c) inputChoiceData :: EventData (InputChoice c) -> c InputStringData :: String -> EventData InputString inputStringData :: EventData InputString -> String VictoryData :: [PlayerInfo] -> EventData Victory victoryData :: EventData Victory -> [PlayerInfo] data EventStatus EvActive :: EventStatus EvDeleted :: EventStatus data EventHandler EH :: EventNumber -> RuleNumber -> Event e -> ((EventNumber, EventData e) -> Nomex ()) -> EventStatus -> EventHandler _eventNumber :: EventHandler -> EventNumber _ruleNumber :: EventHandler -> RuleNumber event :: EventHandler -> Event e handler :: EventHandler -> (EventNumber, EventData e) -> Nomex () _evStatus :: EventHandler -> EventStatus type Msg a = Event (Message a) type MsgData a = EventData (Message a) -- | Type of a rule function. type RuleFunc = Nomex RuleResp -- | Return type of a rule function. it can be either nothing or another -- rule. data RuleResp Void :: RuleResp Meta :: (Rule -> Nomex BoolResp) -> RuleResp data BoolResp BoolResp :: Bool -> BoolResp MsgResp :: (Msg Bool) -> BoolResp -- | An informationnal structure about a rule data Rule Rule :: RuleNumber -> RuleName -> String -> PlayerNumber -> Code -> RuleFunc -> RuleStatus -> Maybe RuleNumber -> Rule _rNumber :: Rule -> RuleNumber _rName :: Rule -> RuleName _rDescription :: Rule -> String _rProposedBy :: Rule -> PlayerNumber _rRuleCode :: Rule -> Code _rRuleFunc :: Rule -> RuleFunc _rStatus :: Rule -> RuleStatus _rAssessedBy :: Rule -> Maybe RuleNumber -- | the status of a rule. data RuleStatus Active :: RuleStatus Pending :: RuleStatus Reject :: RuleStatus data SubmitRule SubmitRule :: RuleName -> RuleDesc -> RuleCode -> SubmitRule -- | informations on players data PlayerInfo PlayerInfo :: PlayerNumber -> String -> PlayerInfo _playerNumber :: PlayerInfo -> PlayerNumber _playerName :: PlayerInfo -> String -- | The state of the game: data Game Game :: GameName -> GameDesc -> [Rule] -> [PlayerInfo] -> [Var] -> [EventHandler] -> [Output] -> [PlayerNumber] -> UTCTime -> Game _gameName :: Game -> GameName _gameDesc :: Game -> GameDesc _rules :: Game -> [Rule] _players :: Game -> [PlayerInfo] _variables :: Game -> [Var] _events :: Game -> [EventHandler] _outputs :: Game -> [Output] _victory :: Game -> [PlayerNumber] _currentTime :: Game -> UTCTime data GameDesc GameDesc :: String -> String -> GameDesc _desc :: GameDesc -> String _agora :: GameDesc -> String displayGame :: Game -> String vName :: Lens Var String vRuleNumber :: Lens Var Int evStatus :: Lens EventHandler EventStatus ruleNumber :: Lens EventHandler RuleNumber eventNumber :: Lens EventHandler EventNumber playerName :: Lens PlayerInfo String playerNumber :: Lens PlayerInfo PlayerNumber rAssessedBy :: Lens Rule (Maybe RuleNumber) rStatus :: Lens Rule RuleStatus rRuleFunc :: Lens Rule RuleFunc rRuleCode :: Lens Rule Code rProposedBy :: Lens Rule PlayerNumber rDescription :: Lens Rule String rName :: Lens Rule RuleName rNumber :: Lens Rule RuleNumber agora :: Lens GameDesc String desc :: Lens GameDesc String currentTime :: Lens Game UTCTime victory :: Lens Game [PlayerNumber] outputs :: Lens Game [Output] events :: Lens Game [EventHandler] variables :: Lens Game [Var] players :: Lens Game [PlayerInfo] rules :: Lens Game [Rule] gameDesc :: Lens Game GameDesc gameName :: Lens Game GameName instance Typeable1 V instance Typeable Player instance Typeable RuleEvent instance Typeable Time instance Typeable EvRule instance Typeable1 Message instance Typeable1 InputChoice instance Typeable InputString instance Typeable Victory instance Typeable RuleStatus instance Typeable SubmitRule instance Typeable PlayerInfo instance Typeable1 Nomex instance Typeable Rule instance Typeable RuleResp instance Typeable Game instance Eq e => Eq (Event e) instance Eq (Message m) instance Eq InputString instance Eq (InputChoice a) instance Eq EvRule instance Eq Victory instance Eq Time instance Show Victory instance Show InputString instance Show Time instance Show a => Show (InputChoice a) instance Show a => Show (Message a) instance Show a => Show (EventData a) instance Show a => Show (Event a) instance Typeable1 Event instance Typeable1 EventData instance Show Player instance Eq Player instance Show RuleEvent instance Eq RuleEvent instance Eq EventStatus instance Show EventStatus instance Eq RuleStatus instance Show RuleStatus instance Show SubmitRule instance Read SubmitRule instance Eq SubmitRule instance Ord SubmitRule instance Data SubmitRule instance Eq PlayerInfo instance Show PlayerInfo instance Show Rule instance Eq GameDesc instance Show GameDesc instance Read GameDesc instance Ord GameDesc instance Show Game instance Read Game instance Ord Game instance Eq Game instance Ord Rule instance Eq Rule instance Show RuleResp instance Ord EventHandler instance Eq EventHandler instance Show EventHandler instance Eq Var instance Show Var instance Show a => Show (Nomex a) instance MonadError String Nomex instance Applicative Nomex instance Functor Nomex instance Monad Nomex -- | All the building blocks to build rules. module Language.Nomyx.Definition -- | variable creation newVar :: (Typeable a, Show a, Eq a) => VarName -> a -> Nomex (Maybe (V a)) newVar_ :: (Typeable a, Show a, Eq a) => VarName -> a -> Nomex (V a) -- | variable reading readVar :: (Typeable a, Show a, Eq a) => (V a) -> Nomex (Maybe a) readVar_ :: (Typeable a, Show a, Eq a) => (V a) -> Nomex a -- | variable writing writeVar :: (Typeable a, Show a, Eq a) => (V a) -> a -> Nomex Bool writeVar_ :: (Typeable a, Show a, Eq a) => (V a) -> a -> Nomex () -- | modify a variable using the provided function modifyVar :: (Typeable a, Show a, Eq a) => (V a) -> (a -> a) -> Nomex () -- | delete variable delVar :: (V a) -> Nomex Bool delVar_ :: (V a) -> Nomex () -- | ArrayVar is an indexed array with a signal attached to warn when the -- array is filled. | each indexed elements starts empty (value=Nothing), -- and when the array is full, the signal is triggered. | This is useful -- to wait for a serie of events to happen, and trigger a computation on -- the collected results. data ArrayVar i a ArrayVar :: (Msg [(i, Maybe a)]) -> (V (Map i (Maybe a))) -> ArrayVar i a -- | initialize an empty ArrayVar newArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> Nomex (ArrayVar i a) -- | initialize an empty ArrayVar, registering a callback that will be -- triggered when the array is filled newArrayVar' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, Maybe a)] -> Nomex ()) -> Nomex (ArrayVar i a) -- | initialize an empty ArrayVar, registering a callback. the callback -- will be triggered when the array is filled, and then the ArrayVar will -- be deleted newArrayVarOnce :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, Maybe a)] -> Nomex ()) -> Nomex (ArrayVar i a) isFullArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> Nomex (Bool) -- | store one value and the given index. If this is the last filled -- element, the registered callbacks are triggered. putArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> i -> a -> Nomex () -- | get the messsage triggered when the array is filled getArrayVarMessage :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> Nomex (Msg [(i, Maybe a)]) -- | get the association array getArrayVarData :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> Nomex ([(i, Maybe a)]) -- | get the association array with only the filled values getArrayVarData' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> Nomex ([(i, a)]) delArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> Nomex () -- | register a callback on an event onEvent :: (Typeable e, Show e, Eq e) => Event e -> ((EventNumber, EventData e) -> Nomex ()) -> Nomex EventNumber -- | register a callback on an event, disregard the event number onEvent_ :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Nomex ()) -> Nomex () -- | set an handler for an event that will be triggered only once onEventOnce :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Nomex ()) -> Nomex EventNumber -- | set an handler for an event that will be triggered only once onEventOnce_ :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Nomex ()) -> Nomex () delEvent :: EventNumber -> Nomex Bool delEvent_ :: EventNumber -> Nomex () delAllEvents :: (Typeable e, Show e, Eq e) => Event e -> Nomex () -- | broadcast a message that can be catched by another rule sendMessage :: (Typeable a, Show a, Eq a) => Msg a -> a -> Nomex () sendMessage_ :: Msg () -> Nomex () -- | subscribe on a message onMessage :: (Typeable m, Show m) => Msg m -> (MsgData m -> Nomex ()) -> Nomex () onMessageOnce :: (Typeable m, Show m) => Msg m -> (MsgData m -> Nomex ()) -> Nomex () -- | on the provided schedule, the supplied function will be called schedule :: (Schedule Freq) -> (UTCTime -> Nomex ()) -> Nomex () executeAndScheduleNext :: (EventData Time -> Nomex ()) -> (Schedule Freq) -> (EventData Time) -> Nomex () schedule_ :: (Schedule Freq) -> Nomex () -> Nomex () schedule' :: [UTCTime] -> (UTCTime -> Nomex ()) -> Nomex () executeAndScheduleNext' :: (EventData Time -> Nomex ()) -> [UTCTime] -> (EventData Time) -> Nomex () schedule'_ :: [UTCTime] -> Nomex () -> Nomex () -- | activate a rule: change its state to Active and execute it activateRule :: RuleNumber -> Nomex Bool activateRule_ :: RuleNumber -> Nomex () -- | reject a rule: change its state to Suppressed and suppresses all its -- environment (events, variables, inputs) the rule can be activated -- again later rejectRule :: RuleNumber -> Nomex Bool rejectRule_ :: RuleNumber -> Nomex () getRules :: Nomex [Rule] getActiveRules :: Nomex [Rule] getRule :: RuleNumber -> Nomex (Maybe Rule) getRulesByNumbers :: [RuleNumber] -> Nomex [Rule] getRuleFuncs :: Nomex [RuleFunc] -- | add a rule to the game, it will have to be activated addRule :: Rule -> Nomex Bool addRule_ :: Rule -> Nomex () addRuleParams :: RuleName -> RuleFunc -> RuleCode -> String -> Nomex RuleNumber getFreeRuleNumber :: Nomex RuleNumber suppressRule :: RuleNumber -> Nomex Bool suppressRule_ :: RuleNumber -> Nomex () suppressAllRules :: Nomex Bool modifyRule :: RuleNumber -> Rule -> Nomex Bool inputChoice :: (Eq c, Show c) => PlayerNumber -> String -> [c] -> c -> Event (InputChoice c) inputChoiceHead :: (Eq c, Show c) => PlayerNumber -> String -> [c] -> Event (InputChoice c) inputChoiceEnum :: (Enum c, Bounded c, Typeable c, Eq c, Show c) => PlayerNumber -> String -> c -> Event (InputChoice c) inputString :: PlayerNumber -> String -> Event InputString -- | triggers a choice input to the user. The result will be sent to the -- callback onInputChoice :: (Typeable a, Eq a, Show a) => String -> [a] -> (EventNumber -> a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputChoice_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | the same, suppress the event after first trigger onInputChoiceOnce :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputChoiceOnce_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | triggers a choice input to the user, using an enumerate as input onInputChoiceEnum :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (EventNumber -> a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputChoiceEnum_ :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | the same, suppress the event after first trigger onInputChoiceEnumOnce_ :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | triggers a string input to the user. The result will be sent to the -- callback onInputString :: String -> (EventNumber -> String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | asks the player pn to answer a question, and feed the callback with -- this data. onInputString_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex () -- | asks the player pn to answer a question, and feed the callback with -- this data. onInputStringOnce_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex () -- | get all the players getPlayers :: Nomex [PlayerInfo] -- | Get a specific player getPlayer :: PlayerNumber -> Nomex (Maybe PlayerInfo) -- | Set the name of a player getPlayerName :: PlayerNumber -> Nomex (Maybe PlayerName) -- | Set the name of a player setPlayerName :: PlayerNumber -> PlayerName -> Nomex Bool modifyPlayerName :: PlayerNumber -> (PlayerName -> PlayerName) -> Nomex Bool -- | Get the total number of playersgetPlayersNumber :: Nomex Int getPlayersNumber :: Nomex Int -- | Get all the players number getAllPlayerNumbers :: Nomex [PlayerNumber] -- | Remove the player from the game (kick) delPlayer :: PlayerNumber -> Nomex Bool -- | set victory to a list of players setVictory :: [PlayerNumber] -> Nomex () -- | give victory to one player giveVictory :: PlayerNumber -> Nomex () -- | outputs a message to one player output :: String -> PlayerNumber -> Nomex () outputAll :: String -> Nomex () getCurrentTime :: Nomex UTCTime -- | allows a rule to retrieve its self number (for auto-deleting for -- example) getSelfRuleNumber :: Nomex RuleNumber getSelfRule :: Nomex Rule getSelfProposedByPlayer :: Nomex PlayerNumber voidRule :: Nomex a -> Nomex RuleResp andMsgBool :: Bool -> (Msg Bool) -> Nomex (Msg Bool) andMsgMsg :: Msg Bool -> Msg Bool -> Nomex (Msg Bool) -- | a default rule defaultRule :: Rule instance Boolean (Nomex BoolResp) module Language.Nomyx.Evaluation type Evaluate a = ErrorT String (State Game) a -- | evaluate an expression. The rule number passed is the number of the -- rule containing the expression. evalExp :: Nomex a -> RuleNumber -> Evaluate a triggerEvent :: (Typeable e, Show e, Eq e) => Event e -> EventData e -> Evaluate Bool triggerEvent_ :: (Typeable e, Show e, Eq e) => Event e -> EventData e -> Evaluate () errorHandler :: String -> Nomex () triggerChoice :: EventNumber -> Int -> Evaluate () execChoiceHandler :: EventNumber -> Int -> EventHandler -> Evaluate () findEvent :: EventNumber -> [EventHandler] -> Maybe (EventHandler) getChoiceEvents :: Evaluate [EventNumber] outputS :: PlayerNumber -> String -> Evaluate () evProposeRule :: Rule -> Evaluate Bool evActivateRule :: RuleNumber -> RuleNumber -> Evaluate Bool evRejectRule :: RuleNumber -> RuleNumber -> Evaluate Bool evAddRule :: Rule -> Evaluate Bool evDelRule :: RuleNumber -> Evaluate Bool evModifyRule :: RuleNumber -> Rule -> Evaluate Bool addPlayer :: PlayerInfo -> Evaluate Bool evDelPlayer :: PlayerNumber -> Evaluate Bool evChangeName :: PlayerNumber -> PlayerName -> Evaluate Bool evDelEvent :: EventNumber -> Evaluate Bool evInputChoice :: (Eq d, Show d, Typeable d, Read d) => Event (InputChoice d) -> d -> Evaluate Bool evTriggerTime :: UTCTime -> Evaluate Bool delVarsRule :: RuleNumber -> Evaluate () delEventsRule :: RuleNumber -> Evaluate () runEvalError :: PlayerNumber -> Evaluate () -> State Game () -- | Voting system module Language.Nomyx.Vote data VoteType a ExclusiveVote :: (Maybe (Alts a)) -> VoteType a NonExclusiveVote :: [Alts a] -> VoteType a class (Eq (Alts a), Show (Alts a), Ord (Alts a), Typeable a) => Votable a where data family Alts a exclusiveWinner _ = Nothing alts :: Votable a => [Alts a] quota :: Votable a => Alts a -> Int -> Int -> Int name :: Votable a => a -> String exclusiveWinner :: Votable a => a -> Maybe (Alts a, Alts a) type ForAgainst = Alts Rule type Vote a = (PlayerNumber, Maybe (Alts a)) type VoteResult a = VoteStats a -> [Alts a] data VoteStats a VoteStats :: Map (Maybe (Alts a)) Int -> Bool -> VoteStats a voteCounts :: VoteStats a -> Map (Maybe (Alts a)) Int voteFinished :: VoteStats a -> Bool data VoteData a VoteData :: Msg [Alts a] -> ArrayVar PlayerNumber (Alts a) -> [EventNumber] -> VoteResult a -> VoteData a msgEnd :: VoteData a -> Msg [Alts a] voteVar :: VoteData a -> ArrayVar PlayerNumber (Alts a) inputNumbers :: VoteData a -> [EventNumber] assessFunction :: VoteData a -> VoteResult a type Assessor a = StateT (VoteData a) Nomex () -- | Perform a vote. voteWith :: Votable a => VoteResult a -> Assessor a -> a -> [Alts a] -> Nomex (Msg [Alts a]) -- | Performs a vote, all the possible alternatives are selected. voteWith_ :: Votable a => VoteResult a -> Assessor a -> a -> Nomex (Msg [Alts a]) -- | assess the vote on every new vote with the assess function, and as -- soon as the vote has an issue (positive of negative), sends a signal assessOnEveryVote :: Votable a => Assessor a -- | assess the vote with the assess function when time is reached, and -- sends a signal with the issue (positive of negative) assessOnTimeLimit :: Votable a => UTCTime -> Assessor a -- | assess the vote with the assess function when time is elapsed, and -- sends a signal with the issue (positive of negative) assessOnTimeDelay :: Votable a => NominalDiffTime -> Assessor a -- | assess the vote only when every body voted. An error is generated if -- the assessing function returns Nothing. assessWhenEverybodyVoted :: Votable a => Assessor a -- | clean events and variables necessary for the vote cleanVote :: Votable a => VoteData a -> Nomex () -- | a quorum is the neccessary number of voters for the validity of the -- vote quorum :: Votable a => Int -> VoteStats a -> Bool -- | adds a quorum to an assessing function withQuorum :: Votable a => VoteResult a -> Int -> VoteResult a -- | assess the vote results according to a unanimity (everybody votes for) unanimity :: Votable a => VoteStats a -> [Alts a] -- | assess the vote results according to an absolute majority (half voters -- plus one, no quorum is needed) majority :: Votable a => VoteStats a -> [Alts a] -- | assess the vote results according to a majority of x (in %) majorityWith :: Votable a => Int -> VoteStats a -> [Alts a] -- | assess the vote results according to a necessary number of positive -- votes numberVotes :: Votable a => Int -> VoteStats a -> [Alts a] -- | return the vote alternatives that are above threshold voteQuota :: Votable a => Int -> VoteStats a -> [Alts a] exclusiveVoteQuota :: Votable a => Int -> VoteStats a -> (Alts a, Alts a) -> Maybe (Alts a) -- | number of people that voted if the voting is finished, total number of -- people that should vote otherwise nbVoters :: Votable a => VoteStats a -> Int totalVoters :: Votable a => VoteStats a -> Int notVoted :: Votable a => VoteStats a -> Int voted :: Votable a => VoteStats a -> Int getVoteStats :: Votable a => [Vote a] -> Bool -> VoteStats a counts :: (Eq a, Ord a) => [a] -> [(a, Int)] data Referendum Referendum :: String -> Referendum referendum :: String -> Nomex () -> RuleFunc data Election Election :: String -> Election elections :: String -> [PlayerInfo] -> (PlayerNumber -> Nomex ()) -> Nomex () instance Typeable Referendum instance Typeable Election instance Typeable1 Alts instance Enum (Alts Referendum) instance Show (Alts Referendum) instance Eq (Alts Referendum) instance Bounded (Alts Referendum) instance Read (Alts Referendum) instance Ord (Alts Referendum) instance Enum (Alts Rule) instance Show (Alts Rule) instance Eq (Alts Rule) instance Bounded (Alts Rule) instance Read (Alts Rule) instance Ord (Alts Rule) instance Ord (Alts Election) instance Eq (Alts Election) instance Show (Alts Election) instance Votable Election instance Votable Referendum instance Votable Rule -- | Basic rules examples. module Language.Nomyx.Rule -- | This rule will activate automatically any new rule. autoActivate :: RuleFunc -- | This rule will forbid any new rule to delete the rule in parameter -- immutableRule :: RuleNumber -> RuleFunc immutableRule rn = return $ -- Meta f where f r = do protectedRule <- getRule rn case -- protectedRule of Just pr -> case _rRuleFunc r of RuleRule paramRule -- -> paramRule pr _ -> return $ BoolResp True Nothing -> return -- $ BoolResp True -- -- A rule will be always legal legal :: RuleFunc -- | A rule will be always illegal illegal :: RuleFunc -- | active metarules are automatically used to evaluate a given rule -- checkWithMetarules :: Rule -> Nomex (Event (Message ForAgainst) -- checkWithMetarules rule = do rs <- getActiveRules (metas :: [Rule -- -> Nomex BoolResp]) <- mapMaybeM maybeMetaRule rs let (evals :: -- [Nomex BoolResp]) = map (meta -> meta rule) metas foldr -- (&&*) true evals maybeMetaRule :: Rule -> Nomex (Maybe (Rule -> Nomex BoolResp)) -- | any new rule will be activate if the rule in parameter returns True onRuleProposed :: (Rule -> Nomex (Msg [ForAgainst])) -> RuleFunc -- | activate or reject a rule activateOrReject :: Rule -> Bool -> Nomex () -- | perform an action for each current players, new players and leaving -- players forEachPlayer :: (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> Nomex () -- | perform the same action for each players, including new players forEachPlayer_ :: (PlayerNumber -> Nomex ()) -> Nomex () -- | create a value initialized for each players manages players joining -- and leaving createValueForEachPlayer :: Int -> V [(Int, Int)] -> Nomex () -- | create a value initialized for each players initialized to zero -- manages players joining and leaving createValueForEachPlayer_ :: V [(Int, Int)] -> Nomex () getValueOfPlayer :: PlayerNumber -> V [(Int, Int)] -> Nomex (Maybe Int) modifyValueOfPlayer :: PlayerNumber -> V [(Int, Int)] -> (Int -> Int) -> Nomex () modifyAllValues :: V [(Int, Int)] -> (Int -> Int) -> Nomex () -- | Player p cannot propose anymore rules noPlayPlayer :: PlayerNumber -> RuleFunc -- | a rule can autodelete itself (generaly after having performed some -- actions) autoDelete :: Nomex () -- | All rules from player p are erased: eraseAllRules :: PlayerNumber -> Nomex Bool -- | This file gives a list of example rules that the players can submit. -- You can copy-paste them in the field Code of the web GUI. Don't -- hesitate to get inspiration from there and create your own rules! module Language.Nomyx.Examples -- | A rule that does nothing nothing :: RuleFunc -- | A rule that says hello to all players helloWorld :: RuleFunc -- | account variable name and type accounts :: V [(PlayerNumber, Int)] -- | Create a bank account for each players createBankAccount :: RuleFunc -- | each player wins X Ecu each day you can also try with minutly -- or monthly instead of daily and everything in the -- time-recurrence package winXEcuPerDay :: Int -> RuleFunc -- | a player wins X Ecu if a rule proposed is accepted winXEcuOnRuleAccepted :: Int -> RuleFunc -- | a player can transfer money to another player it does not accept new -- players or check if balance is positive, to keep the example simple moneyTransfer :: RuleFunc -- | delete a rule delRule :: RuleNumber -> RuleFunc -- | a majority vote, with the folowing parameters: a quorum of 2 voters is -- necessary for the validity of the vote the vote is assessed after -- every vote in case the winner is already known the vote will finish -- anyway after one day voteWithMajority :: RuleFunc king :: V PlayerNumber -- | player pn is the king: we create a variable King to identify him, and -- we prefix his name with King makeKing :: PlayerNumber -> RuleFunc -- | Monarchy: only the king decides which rules to accept or reject monarchy :: RuleFunc -- | Revolution! Hail to the king! This rule suppresses the democracy -- (usually rules 1 and 2), installs the king and activates monarchy. revolution :: PlayerNumber -> RuleFunc -- | set the victory for players having more than X accepted rules victoryXRules :: Int -> RuleFunc victoryXEcu :: Int -> RuleFunc -- | will display the time to all players in 5 seconds displayTime :: RuleFunc -- | Only one player can achieve victory: No group victory. Forbidding -- group victory usually becomes necessary when lowering the voting -- quorum: a coalition of players could simply force a victory -- rule and win the game. noGroupVictory :: RuleFunc -- | Rule that state that you win. Good luck on having this accepted by -- other players ;) iWin :: RuleFunc -- | Change current system (the rules passed in parameter) to absolute -- majority (half participants plus one) returnToDemocracy :: [RuleNumber] -> RuleFunc -- | kick a player and prevent him from returning banPlayer :: PlayerNumber -> RuleFunc referendum :: String -> Nomex () -> RuleFunc -- | triggers a referendum, if the outcome is yes player 2 will be kicked referendumOnKickPlayer :: RuleFunc -- | triggers elections (all players are candidates), the winner becomes -- game master gameMasterElections :: RuleFunc gameMaster :: V PlayerNumber module Language.Nomyx.Test date1 :: UTCTime date2 :: UTCTime date3 :: UTCTime testGame :: Game testRule :: Rule evalRuleFunc :: Nomex () -> () execRuleFuncEvent :: (Eq e, Show e, Typeable e) => Nomex a -> Event e -> EventData e -> Game execRuleFuncGame :: Nomex a -> Game -> Game execRuleFuncEventGame :: (Eq e, Show e, Typeable e) => Nomex a -> Event e -> EventData e -> Game -> Game execRuleFunc :: Nomex a -> Game tests :: [([Char], Bool)] allTests :: Bool testVar1 :: RuleFunc testVarEx1 :: Bool testVar2 :: RuleFunc testVarEx2 :: Bool testVar3 :: RuleFunc testVarEx3 :: Bool testVar4 :: RuleFunc testVarEx4 :: Bool testVar5 :: RuleFunc testVarEx5 :: Bool data Choice Holland :: Choice Sarkozy :: Choice testSingleInput :: RuleFunc testSingleInputEx :: Bool testInputString :: RuleFunc testInputStringEx :: Bool testSendMessage :: RuleFunc testSendMessageEx :: Bool testSendMessage2 :: RuleFunc testSendMessageEx2 :: Bool data Choice2 Me :: Choice2 You :: Choice2 testUserInputWrite :: RuleFunc testUserInputWriteEx :: Bool testActivateRule :: RuleFunc testActivateRuleEx :: Bool testAutoActivateEx :: Bool testTimeEvent :: RuleFunc testTimeEventEx :: Bool testTimeEvent2 :: Nomex () testTimeEventEx2 :: Bool voteGameActions :: Int -> Int -> Int -> Bool -> Evaluate () -> Game voteGame' :: Int -> Int -> Int -> Bool -> RuleFunc -> Game voteGame :: Int -> Int -> Int -> RuleFunc -> Game voteGameTimed :: Int -> Int -> Int -> RuleFunc -> Game testVoteAssessOnVoteComplete1 :: Bool testVoteAssessOnVoteComplete2 :: Bool testVoteAssessOnEveryVote1 :: Bool testVoteAssessOnEveryVote2 :: Bool testVoteAssessOnEveryVote3 :: Bool testVoteAssessOnEveryVote4 :: Bool testVoteMajorityWith :: Bool testVoteNumberPositiveVotes :: Bool testVoteWithQuorum1 :: Bool testVoteWithQuorum2 :: Bool testVoteAssessOnTimeLimit1 :: Bool testVoteAssessOnTimeLimit2 :: Bool testVoteAssessOnTimeLimit3 :: Bool testVoteAssessOnTimeLimit4 :: Bool testVoteAssessOnTimeLimit5 :: Bool testVoteRule :: RuleStatus -> Game -> Bool instance Typeable Choice instance Typeable Choice2 instance Enum Choice instance Show Choice instance Eq Choice instance Bounded Choice instance Enum Choice2 instance Show Choice2 instance Eq Choice2 instance Bounded Choice2 module Language.Nomyx -- | This module implements Game management. a game is a set of rules, and -- results of actions made by players (usually vote results) the module -- manages the effects of rules over each others. module Language.Nomyx.Game data GameEvent GameSettings :: GameName -> GameDesc -> UTCTime -> GameEvent JoinGame :: PlayerNumber -> PlayerName -> GameEvent LeaveGame :: PlayerNumber -> GameEvent ProposeRuleEv :: PlayerNumber -> SubmitRule -> GameEvent InputChoiceResult :: PlayerNumber -> EventNumber -> Int -> GameEvent InputStringResult :: PlayerNumber -> String -> String -> GameEvent OutputPlayer :: PlayerNumber -> String -> GameEvent TimeEvent :: UTCTime -> GameEvent SystemAddRule :: SubmitRule -> GameEvent update :: GameEvent -> StateT LoggedGame IO () update' :: Maybe (RuleCode -> IO RuleFunc) -> GameEvent -> StateT LoggedGame IO () data LoggedGame LoggedGame :: Game -> [TimedEvent] -> LoggedGame _game :: LoggedGame -> Game _gameLog :: LoggedGame -> [TimedEvent] game :: Lens LoggedGame Game gameLog :: Lens LoggedGame [TimedEvent] emptyGame :: GameName -> GameDesc -> UTCTime -> Game -- | An helper function to use the state transformer GameState. It -- additionally sets the current time. execWithGame :: UTCTime -> State LoggedGame () -> LoggedGame -> LoggedGame execWithGame' :: UTCTime -> StateT LoggedGame IO () -> LoggedGame -> IO LoggedGame outputAll :: String -> StateT LoggedGame IO () getLoggedGame :: Game -> (RuleCode -> IO RuleFunc) -> [TimedEvent] -> IO LoggedGame tracePN :: Monad m => Int -> String -> m () getTimes :: EventHandler -> Maybe UTCTime activeRules :: Game -> [Rule] pendingRules :: Game -> [Rule] rejectedRules :: Game -> [Rule] instance Ord PlayerInfo instance Show GameEvent instance Read GameEvent instance Eq GameEvent instance Ord GameEvent instance Show TimedEvent instance Read TimedEvent instance Eq TimedEvent instance Ord TimedEvent instance Read LoggedGame instance Show LoggedGame instance Ord LoggedGame instance Eq LoggedGame