-- 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.6.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 -- | 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 Code = String type OutputNumber = Int type InputNumber = Int data Eff Effect :: Eff NoEffect :: Eff type Effect = Effect type NoEffect = NoEffect -- | A Nomex (Nomyx Expression) allows the players to write rules. within -- the rules, you can access and modify the state of the game. type Nomex = Exp Effect -- | A NomexNE (Nomyx Expression No Effect) is a specialisation of the type -- that guaranties that the instructions will have no effects. type NomexNE = Exp NoEffect data Exp :: Eff -> * -> * NewVar :: VarName -> a -> Nomex (Maybe (V a)) ReadVar :: V a -> NomexNE (Maybe a) WriteVar :: V a -> a -> Nomex Bool DelVar :: (V a) -> Nomex Bool OnEvent :: Event e -> ((EventNumber, e) -> Nomex ()) -> Nomex EventNumber DelEvent :: EventNumber -> Nomex Bool SendMessage :: Msg a -> a -> Nomex () ProposeRule :: RuleInfo -> Nomex Bool ActivateRule :: RuleNumber -> Nomex Bool RejectRule :: RuleNumber -> Nomex Bool AddRule :: RuleInfo -> Nomex Bool ModifyRule :: RuleNumber -> RuleInfo -> Nomex Bool GetRules :: NomexNE [RuleInfo] GetPlayers :: NomexNE [PlayerInfo] SetPlayerName :: PlayerNumber -> PlayerName -> Nomex Bool DelPlayer :: PlayerNumber -> Nomex Bool NewOutput :: Maybe PlayerNumber -> NomexNE String -> Nomex OutputNumber GetOutput :: OutputNumber -> NomexNE (Maybe String) UpdateOutput :: OutputNumber -> NomexNE String -> Nomex Bool DelOutput :: OutputNumber -> Nomex Bool SetVictory :: NomexNE [PlayerNumber] -> Nomex () CurrentTime :: NomexNE UTCTime SelfRuleNumber :: NomexNE RuleNumber Return :: a -> Exp e a Bind :: Exp e a -> (a -> Exp e b) -> Exp e b ThrowError :: String -> Exp Effect a CatchError :: Nomex a -> (String -> Nomex a) -> Nomex a LiftEffect :: NomexNE a -> Nomex a Simu :: Nomex a -> NomexNE Bool -> NomexNE Bool liftEffect :: NomexNE a -> Nomex a -- | a container for a variable name and type data V a V :: String -> V a varName :: V a -> String -- | Composable events data Event a SumEvent :: Event a -> Event a -> Event a AppEvent :: Event (a -> b) -> Event a -> Event b PureEvent :: a -> Event a EmptyEvent :: Event a BaseEvent :: Field a -> Event a -- | Base events data Field a Input :: Maybe InputNumber -> PlayerNumber -> String -> (InputForm a) -> Field a Player :: Player -> Field PlayerInfo RuleEv :: RuleEvent -> Field RuleInfo Time :: UTCTime -> Field UTCTime Message :: Msg a -> Field a Victory :: Field VictoryCond -- | Type agnostic base event data SomeField SomeField :: (Field a) -> SomeField -- | Events parameters data Player Arrive :: Player Leave :: Player data RuleEvent Proposed :: RuleEvent Activated :: RuleEvent Rejected :: RuleEvent Added :: RuleEvent Modified :: RuleEvent Deleted :: RuleEvent data Msg m Msg :: String -> Msg m -- | Input forms data InputForm a Text :: InputForm String TextArea :: InputForm String Button :: InputForm () Radio :: [(a, String)] -> InputForm a Checkbox :: [(a, String)] -> InputForm [a] -- | Type of a rule function. type Rule = Nomex () -- | An informationnal structure about a rule data RuleInfo RuleInfo :: RuleNumber -> RuleName -> String -> PlayerNumber -> Code -> Rule -> RuleStatus -> Maybe RuleNumber -> RuleInfo _rNumber :: RuleInfo -> RuleNumber _rName :: RuleInfo -> RuleName _rDescription :: RuleInfo -> String _rProposedBy :: RuleInfo -> PlayerNumber _rRuleCode :: RuleInfo -> Code _rRule :: RuleInfo -> Rule _rStatus :: RuleInfo -> RuleStatus _rAssessedBy :: RuleInfo -> Maybe RuleNumber -- | the status of a rule. data RuleStatus Active :: RuleStatus Pending :: RuleStatus Reject :: RuleStatus -- | informations on players data PlayerInfo PlayerInfo :: PlayerNumber -> String -> Maybe PlayerNumber -> PlayerInfo _playerNumber :: PlayerInfo -> PlayerNumber _playerName :: PlayerInfo -> String _playAs :: PlayerInfo -> Maybe PlayerNumber data VictoryCond VictoryCond :: RuleNumber -> (NomexNE [PlayerNumber]) -> VictoryCond partial :: String -> Nomex (Maybe a) -> Nomex a concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] playAs :: Lens PlayerInfo (Maybe PlayerNumber) playerName :: Lens PlayerInfo String playerNumber :: Lens PlayerInfo PlayerNumber rAssessedBy :: Lens RuleInfo (Maybe RuleNumber) rStatus :: Lens RuleInfo RuleStatus rRule :: Lens RuleInfo Rule rRuleCode :: Lens RuleInfo Code rProposedBy :: Lens RuleInfo PlayerNumber rDescription :: Lens RuleInfo String rName :: Lens RuleInfo RuleName rNumber :: Lens RuleInfo RuleNumber instance Typeable1 V instance Typeable Player instance Typeable RuleEvent instance Typeable1 Msg instance Typeable1 InputForm instance Typeable RuleStatus instance Typeable PlayerInfo instance Typeable VictoryCond instance Typeable RuleInfo instance Typeable1 Event instance Typeable1 Field instance Eq (Msg e) instance Eq (InputForm e) instance Eq (Field e) instance Show SomeField instance Show (Field a) instance Show (InputForm a) instance Show Player instance Eq Player instance Show RuleEvent instance Eq RuleEvent instance Show (Msg m) instance Eq RuleStatus instance Show RuleStatus instance Eq PlayerInfo instance Show PlayerInfo instance Show VictoryCond instance Show RuleInfo instance Ord PlayerInfo instance Ord RuleInfo instance Eq RuleInfo instance Alternative Event instance Applicative Event instance Functor Event instance (Typeable a, Typeable b) => Show (a -> b) instance Typeable a => Show (Exp Effect a) instance Typeable a => Show (Exp NoEffect a) instance MonadError String Nomex instance Applicative (Exp a) instance Functor (Exp a) instance Monad (Exp a) instance Typeable1 (Exp Effect) instance Typeable1 (Exp NoEffect) -- | All the building blocks to allow rules to build events. module Language.Nomyx.Events -- | register a callback on an event onEvent :: (Typeable e, Show e) => Event e -> ((EventNumber, e) -> Nomex ()) -> Nomex EventNumber -- | register a callback on an event, disregard the event number onEvent_ :: (Typeable e, Show e) => Event e -> (e -> Nomex ()) -> Nomex EventNumber -- | set an handler for an event that will be triggered only once onEventOnce :: (Typeable e, Show e) => Event e -> (e -> Nomex ()) -> Nomex EventNumber delEvent :: EventNumber -> Nomex Bool -- | broadcast a message that can be catched by another rule sendMessage :: (Typeable a, Show a) => Msg a -> a -> Nomex () sendMessage_ :: String -> Nomex () -- | subscribe on a message onMessage :: (Typeable m, Show m) => Msg m -> (m -> Nomex ()) -> Nomex EventNumber onMessageOnce :: (Typeable m, Show m) => Msg m -> (m -> Nomex ()) -> Nomex EventNumber -- | on the provided schedule, the supplied function will be called schedule :: Schedule Freq -> (UTCTime -> Nomex ()) -> Nomex () schedule_ :: Schedule Freq -> Nomex () -> Nomex () schedule' :: [UTCTime] -> (UTCTime -> Nomex ()) -> Nomex () schedule'_ :: [UTCTime] -> Nomex () -> Nomex () getCurrentTime :: NomexNE UTCTime -- | duration oneWeek :: NominalDiffTime -- | duration oneDay :: NominalDiffTime -- | duration oneHour :: NominalDiffTime -- | duration oneMinute :: NominalDiffTime timeEvent :: UTCTime -> Event UTCTime messageEvent :: Typeable a => Msg a -> Event a victoryEvent :: Event VictoryCond playerEvent :: Player -> Event PlayerInfo ruleEvent :: RuleEvent -> Event RuleInfo baseEvent :: Typeable a => Field a -> Event a baseInputEvent :: Typeable a => PlayerNumber -> String -> (InputForm a) -> Field a -- | All the building blocks to allow rules to get inputs. for example, you -- can create a button that will display a message like this: do void $ -- onInputButton_ Click here: (const $ outputAll_ Bravo!) 1 module Language.Nomyx.Inputs -- | Input forms data InputForm a Text :: InputForm String TextArea :: InputForm String Button :: InputForm () Radio :: [(a, String)] -> InputForm a Checkbox :: [(a, String)] -> InputForm [a] -- | 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 EventNumber -- | the same, suppress the event after first trigger onInputRadioOnce :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Nomex ()) -> PlayerNumber -> Nomex EventNumber -- | 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 EventNumber -- | asks the player pn to answer a question, and feed the callback with -- this data. onInputTextOnce :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber 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 EventNumber onInputCheckboxOnce :: (Typeable a, Eq a, Show a) => String -> [(a, String)] -> ([a] -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputButton :: String -> (EventNumber -> () -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputButton_ :: String -> (() -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputButtonOnce :: String -> (() -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputTextarea :: String -> (EventNumber -> String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputTextarea_ :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber onInputTextareaOnce :: String -> (String -> Nomex ()) -> PlayerNumber -> Nomex EventNumber baseInputRadio :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [(c, String)] -> Field c baseInputText :: PlayerNumber -> String -> Field String baseInputCheckbox :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [(c, String)] -> Field [c] baseInputButton :: PlayerNumber -> String -> Field () baseInputTextarea :: PlayerNumber -> String -> Field String inputRadio :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [c] -> c -> Event c inputText :: PlayerNumber -> String -> Event String inputCheckbox :: (Eq c, Show c, Typeable c) => PlayerNumber -> String -> [(c, String)] -> Event [c] inputButton :: PlayerNumber -> String -> Event () inputTextarea :: PlayerNumber -> String -> Event String -- | All the building blocks to allow rules to build variables. for -- example, you can create a variable with: do newMsgVar_ MyMoney -- (0::Int) module Language.Nomyx.Variables -- | a container for a variable name and type data V a V :: String -> V a varName :: V a -> String -- | a MsgVar is a variable with a message attached, allowing to trigger -- registered functions anytime the var if modified data VEvent a VUpdated :: a -> VEvent a VDeleted :: VEvent a data MsgVar a MsgVar :: Msg (VEvent a) -> V a -> MsgVar a message :: MsgVar a -> Msg (VEvent a) variable :: MsgVar a -> V a -- | variable creation newVar :: (Typeable a, Show a) => VarName -> a -> Nomex (Maybe (V a)) newVar_ :: (Typeable a, Show a) => VarName -> a -> Nomex (V a) newVar' :: (Typeable a, Show a) => V a -> a -> Nomex Bool -- | variable reading readVar :: (Typeable a, Show a) => V a -> NomexNE (Maybe a) readVar_ :: (Typeable a, Show a) => V a -> Nomex a -- | variable writing writeVar :: (Typeable a, Show a) => V a -> a -> Nomex Bool -- | modify a variable using the provided function modifyVar :: (Typeable a, Show a) => V a -> (a -> a) -> Nomex Bool -- | delete variable delVar :: V a -> Nomex Bool newMsgVar :: (Typeable a, Show a) => VarName -> a -> Nomex (Maybe (MsgVar a)) newMsgVar_ :: (Typeable a, Show a) => VarName -> a -> Nomex (MsgVar a) newMsgVar' :: (Typeable a, Show a) => MsgVar a -> a -> Nomex Bool readMsgVar :: (Typeable a, Show a) => MsgVar a -> NomexNE (Maybe a) readMsgVar_ :: (Typeable a, Show a) => MsgVar a -> Nomex a writeMsgVar :: (Typeable a, Show a) => MsgVar a -> a -> Nomex Bool modifyMsgVar :: (Typeable a, Show a) => MsgVar a -> (a -> a) -> Nomex Bool delMsgVar :: (Typeable a, Show a) => MsgVar a -> Nomex Bool msgVar :: String -> MsgVar a -- | create a new MsgVar and register callback in case of change (update, -- delete) newMsgVarOnEvent :: (Typeable a, Show a, Eq a) => VarName -> a -> (VEvent a -> Nomex ()) -> Nomex (Maybe (MsgVar a)) onMsgVarEvent :: (Typeable a, Show a) => MsgVar a -> (VEvent a -> Nomex ()) -> Nomex EventNumber -- | adds a callback for each of the MsgVar events: Create, Update, Delete onMsgVarChange :: (Typeable a, Show a, Eq a) => MsgVar a -> (a -> Nomex b) -> (a -> b -> Nomex ()) -> (b -> Nomex ()) -> Nomex EventNumber onMsgVarDelete :: (Typeable a, Show a) => MsgVar a -> Nomex () -> Nomex EventNumber -- | get the messsage triggered when the array is filled getMsgVarMessage :: (Typeable a, Show a) => MsgVar a -> NomexNE (Msg (VEvent a)) -- | get the association array getMsgVarData :: (Typeable a, Show a) => MsgVar a -> NomexNE (Maybe a) getMsgVarData_ :: (Typeable a, Show a) => MsgVar a -> Nomex a getMsgVarName :: (Typeable a, Show 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, Typeable i, Show i) => VarName -> [i] -> Nomex (Maybe (ArrayVar i a)) newArrayVar_ :: (Typeable a, Show a, Typeable i, Show 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 :: (Typeable a, Show a, Eq a, Typeable i, Show i, Ord i) => VarName -> [i] -> (VEvent [(i, Maybe a)] -> Nomex ()) -> Nomex (Maybe (ArrayVar i a)) cleanOnFull :: (Typeable a, Show a, Eq a, Typeable i, Show i, Ord i) => ArrayVar i a -> Nomex () isFullArrayVar_ :: (Typeable a, Show a, Typeable i, Show i, Ord i) => ArrayVar i a -> NomexNE Bool -- | store one value and the given index. If this is the last filled -- element, the registered callbacks are triggered. putArrayVar :: (Typeable a, Show a, Eq a, Typeable i, Show i, Eq i, Ord i) => ArrayVar i a -> i -> a -> Nomex Bool putArrayVar_ :: (Typeable a, Show a, Eq a, Typeable i, Show i, Ord i) => ArrayVar i a -> i -> a -> Nomex () instance Typeable1 VEvent instance Show a => Show (VEvent a) instance Eq a => Eq (VEvent a) -- | All the building blocks to allow rules to produce outputs. for -- example, you can display a message like this: do outputAll_ hello, -- world! module Language.Nomyx.Outputs type OutputNumber = Int -- | outputs a message to one player newOutput :: Maybe PlayerNumber -> NomexNE String -> Nomex OutputNumber -- | outputs a message to one player newOutput_ :: Maybe PlayerNumber -> String -> Nomex OutputNumber -- | output a message to all players outputAll :: NomexNE String -> Nomex OutputNumber -- | output a constant message to all players outputAll_ :: String -> Nomex () -- | get an output by number getOutput :: OutputNumber -> NomexNE (Maybe String) -- | get an output by number, partial version getOutput_ :: OutputNumber -> Nomex String -- | update an output updateOutput :: OutputNumber -> NomexNE String -> Nomex Bool -- | delete an output delOutput :: OutputNumber -> Nomex Bool displayVar :: (Typeable a, Show a) => Maybe PlayerNumber -> MsgVar a -> (Maybe a -> NomexNE String) -> Nomex OutputNumber displayVar' :: (Typeable a, Show a) => Maybe PlayerNumber -> MsgVar a -> (a -> NomexNE String) -> Nomex OutputNumber displaySimpleVar :: (Typeable a, Show a) => Maybe PlayerNumber -> MsgVar a -> String -> Nomex OutputNumber displayArrayVar :: (Typeable a, Show a, Typeable i, Show i) => Maybe PlayerNumber -> ArrayVar i a -> String -> Nomex OutputNumber -- | Basic rules building blocks. for example, you can suppress rule 1 -- with: do suppressRule 1 module Language.Nomyx.Rules type RuleNumber = Int type RuleCode = String data RuleEvent Proposed :: RuleEvent Activated :: RuleEvent Rejected :: RuleEvent Added :: RuleEvent Modified :: RuleEvent Deleted :: RuleEvent -- | the status of a rule. data RuleStatus Active :: RuleStatus Pending :: RuleStatus Reject :: RuleStatus -- | A meta rule is a rule that can juge the legality of another rule. type MetaRule = RuleInfo -> NomexNE Bool -- | 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 :: NomexNE [RuleInfo] getActiveRules :: NomexNE [RuleInfo] getRule :: RuleNumber -> NomexNE (Maybe RuleInfo) getRulesByNumbers :: [RuleNumber] -> NomexNE [RuleInfo] getRuleFuncs :: NomexNE [Nomex ()] -- | add a rule to the game, it will have to be activated addRule :: RuleInfo -> Nomex Bool addRule_ :: RuleInfo -> Nomex () addRuleParams :: RuleName -> Rule -> RuleCode -> String -> Nomex RuleNumber getFreeRuleNumber :: NomexNE RuleNumber suppressRule :: RuleNumber -> Nomex Bool suppressRule_ :: RuleNumber -> Nomex () suppressAllRules :: Nomex Bool modifyRule :: RuleNumber -> RuleInfo -> Nomex Bool -- | This rule will activate automatically any new rule. autoActivate :: Nomex () -- | activate or reject a rule activateOrReject :: RuleInfo -> Bool -> Nomex () -- | simulate the execution of rule sim and then run rule -- test over the result simulate :: Nomex a -> NomexNE Bool -> NomexNE Bool -- | The meta rules are stored in a list variable metaruleVar :: MsgVar [(String, MetaRule)] -- | create the meta rule variable createMetaruleVar :: Nomex () -- | add a new metarule to the list addMetarule :: MetaRule -> String -> Nomex () -- | use the list of meta rules to juge a new rule testWithMetaRules :: RuleInfo -> NomexNE Bool displayMetarules :: Nomex () -- | A rule will be always legal legal :: MetaRule -- | A rule will be always illegal illegal :: MetaRule -- | Player p cannot propose any more rules noPlayPlayer :: PlayerNumber -> MetaRule -- | rule number rn cannot be deleted by any incoming rule we simulate the -- execution of an incoming rule to make sure it doesn't delete the -- immutable rule immutableRule :: RuleNumber -> MetaRule -- | a rule can autodelete itself (generaly after having performed some -- actions) autoDelete :: Nomex () -- | All rules from player p are erased: eraseAllRules :: PlayerNumber -> Nomex Bool -- | allows a rule to retrieve its own number (for auto-deleting for -- example) getSelfRuleNumber :: NomexNE RuleNumber getSelfRule :: NomexNE RuleInfo showRule :: Show a => a -> Exp Effect () -- | All the building blocks to allow rules to manage players. for example, -- you can change the name of player 1 with: do void $ modifyPlayerName 1 -- (King ++) module Language.Nomyx.Players type PlayerNumber = Int type PlayerName = String -- | informations on players data PlayerInfo PlayerInfo :: PlayerNumber -> String -> Maybe PlayerNumber -> PlayerInfo _playerNumber :: PlayerInfo -> PlayerNumber _playerName :: PlayerInfo -> String _playAs :: PlayerInfo -> Maybe PlayerNumber -- | Events parameters data Player Arrive :: Player Leave :: Player playerEvent :: Player -> Event PlayerInfo playerNumber :: Lens PlayerInfo PlayerNumber playerName :: Lens PlayerInfo String -- | get all the players getPlayers :: NomexNE [PlayerInfo] -- | Get a specific player getPlayer :: PlayerNumber -> NomexNE (Maybe PlayerInfo) -- | Set the name of a player getPlayerName :: PlayerNumber -> NomexNE (Maybe PlayerName) -- | Set the name of a player setPlayerName :: PlayerNumber -> PlayerName -> Nomex Bool modifyPlayerName :: PlayerNumber -> (PlayerName -> PlayerName) -> Nomex Bool -- | Get the total number of players getPlayersNumber :: NomexNE Int -- | Get all the players number getAllPlayerNumbers :: NomexNE [PlayerNumber] -- | Remove the player from the game (kick) delPlayer :: PlayerNumber -> Nomex Bool -- | perform an action for each current players, new players and leaving -- players returns the event numbers for arriving players and leaving -- players forEachPlayer :: (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> (PlayerNumber -> Nomex ()) -> Nomex (EventNumber, EventNumber) -- | perform the same action for each players, including new players -- returns the event numbers for arriving players and leaving players forEachPlayer_ :: (PlayerNumber -> Nomex ()) -> Nomex (EventNumber, EventNumber) -- | create a value initialized for each players manages players joining -- and leaving createValueForEachPlayer :: (Typeable a, Show a, Eq a) => a -> MsgVar [(PlayerNumber, a)] -> Nomex (EventNumber, EventNumber) -- | create a value initialized for each players initialized to zero -- manages players joining and leaving createValueForEachPlayer_ :: MsgVar [(PlayerNumber, Int)] -> Nomex (EventNumber, EventNumber) getValueOfPlayer :: (Typeable a, Show a, Eq a) => PlayerNumber -> MsgVar [(PlayerNumber, a)] -> NomexNE (Maybe a) modifyValueOfPlayer :: (Eq a, Show a, Typeable a) => PlayerNumber -> MsgVar [(PlayerNumber, a)] -> (a -> a) -> Nomex Bool modifyAllValues :: (Eq a, Show a, Typeable a) => MsgVar [(PlayerNumber, a)] -> (a -> a) -> Nomex () -- | show a player name based on his number showPlayer :: PlayerNumber -> NomexNE String -- | get the player number of the proposer of the rule getProposerNumber :: NomexNE PlayerNumber getProposerNumber_ :: Nomex PlayerNumber -- | set victory to a list of players setVictory :: NomexNE [PlayerNumber] -> Nomex () -- | give victory to one player giveVictory :: PlayerNumber -> Nomex () -- | 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 RuleInfo 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 -> Maybe UTCTime -> VoteData a msgEnd :: VoteData a -> Msg [Alts a] voteVar :: VoteData a -> ArrayVar PlayerNumber (Alts a) inputNumbers :: VoteData a -> [EventNumber] assessFunction :: VoteData a -> VoteResult a timeLimit :: VoteData a -> Maybe UTCTime 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 EventNumber -- | 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] -- | the winners are the x vote alternatives with the more votes firstXBest :: Votable a => Int -> VoteStats a -> [Alts a] takeInGroups :: Int -> [[a]] -> [a] -- | the winner is the vote alternative with the more votes firstBest :: Votable a => VoteStats a -> [Alts a] sortWith :: Ord b => (a -> b) -> [a] -> [a] -- | return the vote alternatives that are above threshold voteQuota :: Votable a => Int -> VoteStats a -> [Alts a] -- | in case of exclusive winner 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 => (Maybe PlayerNumber) -> String -> ArrayVar PlayerNumber (Alts a) -> Nomex EventNumber showChoice :: Votable a => Maybe (Alts a) -> String showChoices :: Votable a => [Alts a] -> String showOnGoingVote :: Votable a => String -> [(PlayerNumber, Maybe (Alts a))] -> NomexNE String showFinishedVote :: Votable a => [(PlayerNumber, Maybe (Alts a))] -> NomexNE String showVote :: Votable a => (PlayerNumber, Maybe (Alts a)) -> NomexNE (String, String) displayVoteResult :: Votable a => String -> VoteData a -> Nomex OutputNumber -- | any new rule will be activate if the rule in parameter returns For onRuleProposed :: (RuleInfo -> Nomex (Msg [ForAgainst])) -> Rule data Referendum Referendum :: String -> Referendum referendum :: String -> Nomex () -> Rule data Election Election :: String -> Election elections :: String -> [PlayerInfo] -> (PlayerNumber -> Nomex ()) -> Nomex () voteEvent :: UTCTime -> [PlayerNumber] -> Event ([Maybe Bool]) singleVote :: UTCTime -> PlayerNumber -> Event (Maybe Bool) vote :: UTCTime -> [PlayerNumber] -> Event Bool unanimity' :: [Maybe Bool] -> Bool callVote :: UTCTime -> 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 RuleInfo) instance Show (Alts RuleInfo) instance Eq (Alts RuleInfo) instance Bounded (Alts RuleInfo) instance Read (Alts RuleInfo) instance Ord (Alts RuleInfo) instance Ord (Alts Election) instance Eq (Alts Election) instance Show (Alts Election) instance Votable Election instance Votable Referendum instance Votable RuleInfo -- | This module re-exports the elements necessary to compose a Nomyx rule. module Language.Nomyx -- | 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 :: Rule -- | A rule that says hello to all players helloWorld :: Rule -- | account variable name and type accounts :: MsgVar [(PlayerNumber, Int)] -- | Create a bank account for each players createBankAccount :: Rule -- | 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 -> Rule -- | a player wins X Ecu if a rule proposed is accepted winXEcuOnRuleAccepted :: Int -> Rule -- | 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 :: Rule -- | delete a rule delRule :: RuleNumber -> Rule -- | 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 :: Rule king :: MsgVar PlayerNumber -- | player pn is the king: we create a variable King to identify him, and -- we prefix his name with King makeKing :: PlayerNumber -> Rule -- | Monarchy: only the king decides which rules to accept or reject monarchy :: Rule -- | Revolution! Hail to the king! This rule suppresses the democracy -- (usually rules 1 and 2), installs the king and activates monarchy. revolution :: PlayerNumber -> Rule -- | will display the time to all players in 5 seconds displayTime :: Rule -- | 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 noGroupVictory = -- ruleFunc $ onEvent_ Victory $ (VictoryData ps) -> when (length ps -- >1) $ setVictory [] -- -- Rule that state that you win. Good luck on having this accepted by -- other players ;) iWin :: Rule -- | Change current system (the rules passed in parameter) to absolute -- majority (half participants plus one) returnToDemocracy :: [RuleNumber] -> Rule -- | set the victory for players having more than X accepted rules victoryXRules :: Int -> Rule victoryXEcu :: Int -> Rule -- | kick a player and prevent him from returning banPlayer :: PlayerNumber -> Rule referendum :: String -> Nomex () -> Rule -- | triggers a referendum, if the outcome is yes player 2 will be kicked referendumOnKickPlayer :: Rule -- | triggers elections (all players are candidates), the winner becomes -- game master gameMasterElections :: Rule gameMaster :: MsgVar PlayerNumber -- | display a button and greets you when pressed (for player 1) bravoButton :: Rule enterHaiku :: Rule -- | Permanently display the bank accounts displayBankAccount :: Rule instance Typeable Castle instance Show Castle instance Eq Castle