-- 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.3.1 module Paths_Nomyx_Language version :: Version getBinDir :: IO FilePath getLibDir :: IO FilePath getDataDir :: IO FilePath getLibexecDir :: IO FilePath getDataFileName :: FilePath -> IO FilePath getSysconfDir :: 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 sel :: [a] -> [Int] -> [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 type OutputNumber = Int -- | 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 ModifyRule :: RuleNumber -> Rule -> Nomex Bool GetRules :: Nomex [Rule] GetPlayers :: Nomex [PlayerInfo] SetPlayerName :: PlayerNumber -> PlayerName -> Nomex Bool DelPlayer :: PlayerNumber -> Nomex Bool NewOutput :: PlayerNumber -> String -> Nomex OutputNumber UpdateOutput :: OutputNumber -> String -> Nomex Bool DelOutput :: OutputNumber -> Nomex Bool SetVictory :: [PlayerNumber] -> 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 :: RuleNumber -> String -> a -> Var _vRuleNumber :: Var -> RuleNumber _vName :: Var -> String vData :: Var -> 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 Victory data Input a Input :: PlayerNumber -> String -> (InputForm a) -> Input a data InputForm a Radio :: [(a, String)] -> InputForm a Text :: InputForm a TextArea :: InputForm a Button :: InputForm a Checkbox :: [(a, String)] -> InputForm a -- | events names data Event a Player :: Player -> Event Player RuleEv :: RuleEvent -> Event RuleEvent Time :: UTCTime -> Event Time Message :: String -> Event (Message m) InputEv :: Input a -> Event (Input a) Victory :: Event Victory data InputData a RadioData :: a -> InputData a CheckboxData :: [a] -> InputData a TextData :: String -> InputData a TextAreaData :: String -> InputData a ButtonData :: InputData a data UInputData URadioData :: Int -> UInputData UCheckboxData :: [Int] -> UInputData UTextData :: String -> UInputData UTextAreaData :: String -> UInputData UButtonData :: UInputData -- | 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 InputData :: InputData a -> EventData (Input a) inputData :: EventData (Input a) -> InputData a VictoryData :: [PlayerInfo] -> EventData Victory victoryData :: EventData Victory -> [PlayerInfo] data Status SActive :: Status SDeleted :: Status data EventHandler EH :: EventNumber -> RuleNumber -> Event e -> ((EventNumber, EventData e) -> Nomex ()) -> Status -> EventHandler _eventNumber :: EventHandler -> EventNumber _ruleNumber :: EventHandler -> RuleNumber event :: EventHandler -> Event e handler :: EventHandler -> (EventNumber, EventData e) -> Nomex () _evStatus :: EventHandler -> Status type Msg a = Event (Message a) type MsgData a = EventData (Message a) data Output Output :: OutputNumber -> PlayerNumber -> PlayerNumber -> String -> Status -> Output _outputNumber :: Output -> OutputNumber _oRuleNumber :: Output -> PlayerNumber _oPlayerNumber :: Output -> PlayerNumber _output :: Output -> String _oStatus :: Output -> Status data Log Log :: Maybe PlayerNumber -> UTCTime -> String -> Log _lPlayerNumber :: Log -> Maybe PlayerNumber _lTime :: Log -> UTCTime _lMsg :: Log -> String -- | 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] -> [Log] -> 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] _logs :: Game -> [Log] _currentTime :: Game -> UTCTime data GameDesc GameDesc :: String -> String -> GameDesc _desc :: GameDesc -> String _agora :: GameDesc -> String displayGame :: Game -> String oStatus :: Lens Output Status output :: Lens Output String oPlayerNumber :: Lens Output PlayerNumber oRuleNumber :: Lens Output PlayerNumber outputNumber :: Lens Output OutputNumber vName :: Lens Var String vRuleNumber :: Lens Var RuleNumber evStatus :: Lens EventHandler Status 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 logs :: Lens Game [Log] 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 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 (InputForm e) instance Eq e => Eq (Input e) instance Eq e => Eq (Event e) instance Eq (Message m) instance Eq EvRule instance Eq Victory instance Eq Time instance Show Victory instance Show Time instance Show a => Show (Message a) instance Show a => Show (InputData a) instance Show a => Show (EventData a) instance Show a => Show (Input a) instance Show a => Show (InputForm a) instance Show a => Show (Event a) instance Typeable1 InputForm instance Typeable1 Input instance Typeable1 Event instance Typeable1 EventData instance Show Player instance Eq Player instance Show RuleEvent instance Eq RuleEvent instance Show UInputData instance Read UInputData instance Eq UInputData instance Ord UInputData instance Eq Status instance Show Status instance Show Output instance Show Log 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 Typeable 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 () data VEvent a VUpdated :: a -> VEvent a VDeleted :: VEvent a data MsgVar a MsgVar :: (Msg (VEvent a)) -> (V a) -> MsgVar a msgVar :: String -> MsgVar a newMsgVar :: (Typeable a, Show a, Eq a) => VarName -> a -> Nomex (Maybe (MsgVar a)) newMsgVar_ :: (Typeable a, Show a, Eq a) => VarName -> a -> Nomex (MsgVar a) newMsgVar' :: (Typeable a, Show a, Eq a) => VarName -> a -> (VEvent a -> Nomex ()) -> Nomex (Maybe (MsgVar a)) writeMsgVar :: (Typeable a, Show a, Eq a) => MsgVar a -> a -> Nomex Bool writeMsgVar_ :: (Typeable a, Show a, Eq a) => MsgVar a -> a -> Nomex () readMsgVar :: (Typeable a, Show a, Eq a) => MsgVar a -> Nomex (Maybe a) readMsgVar_ :: (Typeable a, Show a, Eq a) => MsgVar a -> Nomex a modifyMsgVar :: (Typeable a, Show a, Eq a) => MsgVar a -> (a -> a) -> Nomex () delMsgVar :: (Typeable a, Show a, Eq a) => MsgVar a -> Nomex Bool onMsgVarChange :: (Typeable a, Show a, Eq a) => MsgVar a -> (VEvent a -> Nomex ()) -> Nomex () onMsgVarEvent :: (Typeable a, Show a, Eq a) => MsgVar a -> (a -> Nomex b) -> (a -> b -> Nomex ()) -> (b -> Nomex ()) -> Nomex () -- | get the messsage triggered when the array is filled getMsgVarMessage :: (Typeable a, Show a, Eq a) => (MsgVar a) -> Nomex (Msg (VEvent a)) -- | get the association array getMsgVarData :: (Typeable a, Show a, Eq a) => (MsgVar a) -> Nomex (Maybe a) getMsgVarData_ :: (Typeable a, Show a, Eq a) => (MsgVar a) -> Nomex a getMsgVarName :: (Typeable a, Show a, Eq a) => (MsgVar a) -> String -- | ArrayVar is an indexed array with a signal attached triggered at every -- change. | each indexed elements starts empty (value=Nothing). type ArrayVar i a = MsgVar [(i, Maybe a)] -- | initialize an empty ArrayVar newArrayVar :: (Typeable a, Show a, Eq a, Typeable i, Show i, Eq i) => VarName -> [i] -> Nomex (Maybe (ArrayVar i a)) newArrayVar_ :: (Typeable a, Show a, Eq a, Typeable i, Show i, Eq i) => VarName -> [i] -> Nomex (ArrayVar i a) -- | initialize an empty ArrayVar, registering a callback that will be -- triggered at every change newArrayVar' :: (Typeable a, Show a, Eq a, Typeable i, Show i, Eq i) => VarName -> [i] -> (VEvent [(i, Maybe a)] -> Nomex ()) -> Nomex (Maybe (ArrayVar i a)) -- | initialize an empty ArrayVar, registering a callback. the ArrayVar -- will be deleted when full newArrayVarOnce :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> (VEvent [(i, Maybe a)] -> Nomex ()) -> Nomex (Maybe (ArrayVar i a)) cleanOnFull :: (Typeable a, Show a, Eq a, Ord i, Typeable i, Show i) => (ArrayVar i a) -> Nomex () 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 Bool putArrayVar_ :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => (ArrayVar i a) -> 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 inputRadio :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [c] -> c -> Event (Input c) inputRadioHead :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [c] -> Event (Input c) inputRadioEnum :: (Enum c, Bounded c, Typeable c, Eq c, Show c) => PlayerNumber -> String -> c -> Event (Input c) inputRadioData :: Show c => EventData (Input c) -> c -- | triggers a choice input to the user. The result will be sent to the -- callback onInputRadio :: (Typeable a, Eq a, Show a) => String -> [a] -> (EventNumber -> a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputRadio_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | the same, suppress the event after first trigger onInputRadioOnce :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputRadioOnce_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | triggers a choice input to the user, using an enumerate as input onInputRadioEnum :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (EventNumber -> a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | the same, disregard the event number onInputRadioEnum_ :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Nomex ()) -> PlayerNumber -> Nomex () -- | the same, suppress the event after first trigger onInputRadioEnumOnce_ :: (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Nomex ()) -> PlayerNumber -> Nomex () inputText :: PlayerNumber -> String -> Event (Input String) inputTextData :: EventData (Input String) -> String -- | triggers a string input to the user. The result will be sent to the -- callback onInputText :: String -> (EventNumber -> String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | asks the player pn to answer a question, and feed the callback with -- this data. onInputText_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex () -- | asks the player pn to answer a question, and feed the callback with -- this data. onInputTextOnce_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex () inputCheckboxData :: Show c => EventData (Input c) -> [c] inputCheckbox :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [(c, String)] -> Event (Input c) onInputCheckbox :: (Typeable a, Eq a, Show a) => String -> [(a, String)] -> (EventNumber -> [a] -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputCheckbox_ :: (Typeable a, Eq a, Show a) => String -> [(a, String)] -> ([a] -> Nomex ()) -> PlayerNumber -> Nomex () inputButtonData :: EventData (Input ()) -> () inputButton :: PlayerNumber -> String -> Event (Input ()) onInputButton :: String -> (EventNumber -> () -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputButton_ :: String -> (() -> Nomex ()) -> PlayerNumber -> Nomex () inputTextareaData :: EventData (Input String) -> String inputTextarea :: PlayerNumber -> String -> Event (Input String) onInputTextarea :: String -> (EventNumber -> String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputTextarea_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex () onInputTextareaOnce_ :: 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 -- | outputs a message to one player newOutput :: String -> PlayerNumber -> Nomex OutputNumber newOutput_ :: String -> PlayerNumber -> Nomex () outputAll :: String -> Nomex () updateOutput :: OutputNumber -> String -> Nomex Bool updateOutput_ :: OutputNumber -> String -> Nomex () delOutput :: OutputNumber -> Nomex Bool delOutput_ :: OutputNumber -> Nomex () displayVar :: (Typeable a, Show a, Eq a) => PlayerNumber -> MsgVar a -> (a -> String) -> Nomex () displaySimpleVar :: (Typeable a, Show a, Eq a) => PlayerNumber -> String -> MsgVar a -> Nomex () displayArrayVar :: (Typeable a, Show a, Eq a, Typeable i, Show i, Eq i) => PlayerNumber -> String -> ArrayVar i a -> Nomex () showArrayVar :: (Show a, Show i) => String -> [(i, a)] -> String -- | set victory to a list of players setVictory :: [PlayerNumber] -> Nomex () -- | give victory to one player giveVictory :: PlayerNumber -> Nomex () getCurrentTime :: Nomex UTCTime -- | allows a rule to retrieve its own 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) partial :: String -> Nomex (Maybe a) -> Nomex a -- | a default rule defaultRule :: Rule instance Typeable1 VEvent instance Show a => Show (VEvent a) instance Eq a => Eq (VEvent a) instance Boolean (Nomex BoolResp) -- | 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)) -- | 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 -> MsgVar [(Int, Int)] -> Nomex () -- | create a value initialized for each players initialized to zero -- manages players joining and leaving createValueForEachPlayer_ :: MsgVar [(Int, Int)] -> Nomex () getValueOfPlayer :: PlayerNumber -> MsgVar [(Int, Int)] -> Nomex (Maybe Int) modifyValueOfPlayer :: PlayerNumber -> MsgVar [(Int, Int)] -> (Int -> Int) -> Nomex () modifyAllValues :: MsgVar [(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 showPlayer :: Nomex (PlayerNumber -> String) 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 triggerHandler :: (Typeable e, Show e, Eq e) => EventData e -> EventHandler -> Evaluate () triggerEvent_ :: (Typeable e, Show e, Eq e) => Event e -> EventData e -> Evaluate () errorHandler :: RuleNumber -> EventNumber -> String -> Evaluate () triggerInput :: EventNumber -> UInputData -> Evaluate () execInputHandler :: UInputData -> EventHandler -> Evaluate () findEvent :: EventNumber -> [EventHandler] -> Maybe (EventHandler) getChoiceEvents :: Evaluate [EventNumber] evProposeRule :: Rule -> Evaluate Bool evActivateRule :: RuleNumber -> RuleNumber -> Evaluate Bool evRejectRule :: RuleNumber -> RuleNumber -> Evaluate Bool evAddRule :: Rule -> Evaluate Bool evModifyRule :: RuleNumber -> Rule -> Evaluate Bool addPlayer :: PlayerInfo -> Evaluate Bool evDelPlayer :: PlayerNumber -> Evaluate Bool evChangeName :: PlayerNumber -> PlayerName -> Evaluate Bool evDelEvent :: EventNumber -> Evaluate Bool evTriggerTime :: UTCTime -> Evaluate Bool delVarsRule :: RuleNumber -> Evaluate () delEventsRule :: RuleNumber -> Evaluate () evNewOutput :: PlayerNumber -> RuleNumber -> String -> Evaluate OutputNumber evUpdateOutput :: OutputNumber -> String -> Evaluate Bool evDelOutput :: OutputNumber -> Evaluate Bool logPlayer :: PlayerNumber -> String -> Evaluate () logAll :: String -> Evaluate () log :: Maybe PlayerNumber -> String -> 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)] displayVoteVar :: Votable a => PlayerNumber -> String -> ArrayVar PlayerNumber (Alts a) -> Nomex () showChoice :: Votable a => Maybe (Alts a) -> String showChoices :: Votable a => [(Alts a)] -> String showVotes :: Votable a => String -> (PlayerNumber -> String) -> [(PlayerNumber, Maybe (Alts a))] -> String showVotes' :: Votable a => (PlayerNumber -> String) -> [(PlayerNumber, Maybe (Alts a))] -> String displayVoteResult :: Votable a => String -> VoteData a -> Nomex () -- | any new rule will be activate if the rule in parameter returns True onRuleProposed :: (Rule -> Nomex (Msg [ForAgainst])) -> RuleFunc 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 -- | 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 :: MsgVar [(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 -- | display a button and greets you when pressed (for player 1) bravoButton :: RuleFunc enterHaiku :: RuleFunc -- | Permanently display the bank accounts displayBankAccount :: RuleFunc 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 testMultipleInputs :: RuleFunc testMultipleInputsEx :: 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 isOutput :: String -> 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 InputResult :: PlayerNumber -> EventNumber -> UInputData -> GameEvent GLog :: (Maybe 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 -- | A 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 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] data UInputData URadioData :: Int -> UInputData UCheckboxData :: [Int] -> UInputData UTextData :: String -> UInputData UTextAreaData :: String -> UInputData UButtonData :: UInputData 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