Safe Haskell | None |
---|
All the building blocks to build rules and basic rules examples.
- newVar :: (Typeable a, Show a, Eq a) => VarName -> a -> Exp (Maybe (V a))
- newVar_ :: (Typeable a, Show a, Eq a) => VarName -> a -> Exp (V a)
- readVar :: (Typeable a, Show a, Eq a) => V a -> Exp (Maybe a)
- readVar_ :: forall a. (Typeable a, Show a, Eq a) => V a -> Exp a
- writeVar :: (Typeable a, Show a, Eq a) => V a -> a -> Exp Bool
- writeVar_ :: (Typeable a, Show a, Eq a) => V a -> a -> Exp ()
- modifyVar :: (Typeable a, Show a, Eq a) => V a -> (a -> a) -> Exp ()
- delVar :: V a -> Exp Bool
- delVar_ :: V a -> Exp ()
- data ArrayVar i a = ArrayVar (Event (Message [(i, a)])) (V (Map i (Maybe a)))
- newArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> Exp (ArrayVar i a)
- newArrayVar' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, a)] -> Exp ()) -> Exp (ArrayVar i a)
- newArrayVarOnce :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, a)] -> Exp ()) -> Exp (ArrayVar i a)
- putArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> i -> a -> Exp ()
- getArrayVarMessage :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp (Event (Message [(i, a)]))
- getArrayVarData :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp [(i, Maybe a)]
- getArrayVarData' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp [(i, a)]
- delArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp ()
- onEvent :: (Typeable e, Show e, Eq e) => Event e -> ((EventNumber, EventData e) -> Exp ()) -> Exp EventNumber
- onEvent_ :: forall e. (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp ()
- onEventOnce :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp EventNumber
- onEventOnce_ :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp ()
- delEvent :: EventNumber -> Exp Bool
- delEvent_ :: EventNumber -> Exp ()
- delAllEvents :: (Typeable e, Show e, Eq e) => Event e -> Exp ()
- sendMessage :: (Typeable a, Show a, Eq a) => Event (Message a) -> a -> Exp ()
- sendMessage_ :: Event (Message ()) -> Exp ()
- onMessage :: (Typeable m, Show m) => Event (Message m) -> (EventData (Message m) -> Exp ()) -> Exp ()
- onMessageOnce :: (Typeable m, Show m) => Event (Message m) -> (EventData (Message m) -> Exp ()) -> Exp ()
- schedule :: Schedule Freq -> (UTCTime -> Exp ()) -> Exp ()
- schedule_ :: Schedule Freq -> Exp () -> Exp ()
- schedule' :: [UTCTime] -> (UTCTime -> Exp ()) -> Exp ()
- schedule'_ :: [UTCTime] -> Exp () -> Exp ()
- activateRule :: RuleNumber -> Exp Bool
- activateRule_ :: RuleNumber -> Exp ()
- rejectRule :: RuleNumber -> Exp Bool
- rejectRule_ :: RuleNumber -> Exp ()
- getRules :: Exp [Rule]
- getActiveRules :: Exp [Rule]
- getRule :: RuleNumber -> Exp (Maybe Rule)
- getRulesByNumbers :: [RuleNumber] -> Exp [Rule]
- getRuleFuncs :: Exp [RuleFunc]
- addRule :: Rule -> Exp Bool
- addRule_ :: Rule -> Exp ()
- addRuleParams_ :: RuleName -> RuleFunc -> RuleCode -> RuleNumber -> String -> Exp ()
- suppressRule :: RuleNumber -> Exp Bool
- suppressRule_ :: RuleNumber -> Exp ()
- suppressAllRules :: Exp Bool
- modifyRule :: RuleNumber -> Rule -> Exp 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 :: forall c. (Enum c, Bounded c, Typeable c, Eq c, Show c) => PlayerNumber -> String -> c -> Event (InputChoice c)
- inputString :: PlayerNumber -> String -> Event InputString
- onInputChoice :: (Typeable a, Eq a, Show a) => String -> [a] -> (EventNumber -> a -> Exp ()) -> PlayerNumber -> Exp EventNumber
- onInputChoice_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp ()
- onInputChoiceOnce :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp EventNumber
- onInputChoiceOnce_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp ()
- onInputChoiceEnum :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (EventNumber -> a -> Exp ()) -> PlayerNumber -> Exp EventNumber
- onInputChoiceEnum_ :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Exp ()) -> PlayerNumber -> Exp ()
- onInputChoiceEnumOnce_ :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Exp ()) -> PlayerNumber -> Exp ()
- onInputString :: String -> (EventNumber -> String -> Exp ()) -> PlayerNumber -> Exp EventNumber
- onInputString_ :: String -> (String -> Exp ()) -> PlayerNumber -> Exp ()
- onInputStringOnce_ :: String -> (String -> Exp ()) -> PlayerNumber -> Exp ()
- setVictory :: [PlayerNumber] -> Exp ()
- giveVictory :: PlayerNumber -> Exp ()
- getPlayers :: Exp [PlayerInfo]
- getPlayersNumber :: Exp Int
- getAllPlayerNumbers :: Exp [PlayerNumber]
- output :: String -> PlayerNumber -> Exp ()
- outputAll :: String -> Exp ()
- getCurrentTime :: Exp UTCTime
- getSelfRuleNumber :: Exp RuleNumber
- autoActivate :: RuleFunc
- immutableRule :: RuleNumber -> RuleFunc
- legal :: RuleFunc
- illegal :: RuleFunc
- simpleApplicationRule :: RuleFunc
- autoMetarules :: Rule -> Exp RuleResponse
- applicationMetaRule :: RuleFunc
- applyRule :: Rule -> Rule -> Exp Bool
- data ForAgainst
- vote :: ([(PlayerNumber, ForAgainst)] -> Bool) -> RuleFunc
- unanimity :: [(PlayerNumber, ForAgainst)] -> Bool
- majority :: [(PlayerNumber, ForAgainst)] -> Bool
- activateOrReject :: Rule -> Bool -> Exp ()
- voteWithTimeLimit :: ([(PlayerNumber, ForAgainst)] -> Bool) -> UTCTime -> RuleFunc
- createValueForEachPlayer :: Int -> String -> Exp ()
- createValueForEachPlayer_ :: String -> Exp ()
- modifyValueOfPlayer :: PlayerNumber -> String -> (Int -> Int) -> Exp ()
- modifyAllValues :: String -> (Int -> Int) -> Exp ()
- noPlayPlayer :: PlayerNumber -> RuleFunc
- autoDelete :: Exp ()
- eraseAllRules :: PlayerNumber -> Exp Bool
- mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
- parse822Time :: String -> UTCTime
- sndMaybe :: (a, Maybe b) -> Maybe (a, b)
- andrr :: RuleResponse -> RuleResponse -> Exp RuleResponse
- andrrs :: [RuleResponse] -> Exp RuleResponse
- (&&.) :: RuleFunc -> RuleFunc -> RuleFunc
- defaultRule :: Rule
Variables
modifyVar :: (Typeable a, Show a, Eq a) => V a -> (a -> a) -> Exp ()Source
modify a variable using the provided function
Variable arrays
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.
newArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> Exp (ArrayVar i a)Source
initialize an empty ArrayVar
newArrayVar' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, a)] -> Exp ()) -> Exp (ArrayVar i a)Source
initialize an empty ArrayVar, registering a callback that will be triggered when the array is filled
newArrayVarOnce :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => VarName -> [i] -> ([(i, a)] -> Exp ()) -> Exp (ArrayVar i a)Source
initialize an empty ArrayVar, registering a callback. the callback will be triggered when the array is filled, and then the ArrayVar will be deleted
putArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> i -> a -> Exp ()Source
store one value and the given index. If this is the last filled element, the registered callbacks are triggered.
getArrayVarMessage :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp (Event (Message [(i, a)]))Source
get the messsage triggered when the array is filled
getArrayVarData :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp [(i, Maybe a)]Source
get the association array
getArrayVarData' :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp [(i, a)]Source
get the association array with only the filled values
delArrayVar :: (Ord i, Typeable a, Show a, Eq a, Typeable i, Show i) => ArrayVar i a -> Exp ()Source
Events
onEvent :: (Typeable e, Show e, Eq e) => Event e -> ((EventNumber, EventData e) -> Exp ()) -> Exp EventNumberSource
register a callback on an event
onEvent_ :: forall e. (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp ()Source
register a callback on an event, disregard the event number
onEventOnce :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp EventNumberSource
set an handler for an event that will be triggered only once
onEventOnce_ :: (Typeable e, Show e, Eq e) => Event e -> (EventData e -> Exp ()) -> Exp ()Source
set an handler for an event that will be triggered only once
delEvent :: EventNumber -> Exp BoolSource
delEvent_ :: EventNumber -> Exp ()Source
sendMessage :: (Typeable a, Show a, Eq a) => Event (Message a) -> a -> Exp ()Source
broadcast a message that can be catched by another rule
sendMessage_ :: Event (Message ()) -> Exp ()Source
onMessage :: (Typeable m, Show m) => Event (Message m) -> (EventData (Message m) -> Exp ()) -> Exp ()Source
subscribe on a message
onMessageOnce :: (Typeable m, Show m) => Event (Message m) -> (EventData (Message m) -> Exp ()) -> Exp ()Source
schedule :: Schedule Freq -> (UTCTime -> Exp ()) -> Exp ()Source
on the provided schedule, the supplied function will be called
schedule'_ :: [UTCTime] -> Exp () -> Exp ()Source
Rule management
activateRule :: RuleNumber -> Exp BoolSource
activate a rule: change its state to Active and execute it
activateRule_ :: RuleNumber -> Exp ()Source
rejectRule :: RuleNumber -> Exp BoolSource
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 -> Exp ()Source
getActiveRules :: Exp [Rule]Source
getRulesByNumbers :: [RuleNumber] -> Exp [Rule]Source
addRuleParams_ :: RuleName -> RuleFunc -> RuleCode -> RuleNumber -> String -> Exp ()Source
suppressRule :: RuleNumber -> Exp BoolSource
suppressRule_ :: RuleNumber -> Exp ()Source
modifyRule :: RuleNumber -> Rule -> Exp BoolSource
Inputs
inputChoice :: (Eq c, Show c) => PlayerNumber -> String -> [c] -> c -> Event (InputChoice c)Source
inputChoiceHead :: (Eq c, Show c) => PlayerNumber -> String -> [c] -> Event (InputChoice c)Source
inputChoiceEnum :: forall c. (Enum c, Bounded c, Typeable c, Eq c, Show c) => PlayerNumber -> String -> c -> Event (InputChoice c)Source
inputString :: PlayerNumber -> String -> Event InputStringSource
onInputChoice :: (Typeable a, Eq a, Show a) => String -> [a] -> (EventNumber -> a -> Exp ()) -> PlayerNumber -> Exp EventNumberSource
triggers a choice input to the user. The result will be sent to the callback
onInputChoice_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp ()Source
the same, disregard the event number
onInputChoiceOnce :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp EventNumberSource
the same, suppress the event after first trigger
onInputChoiceOnce_ :: (Typeable a, Eq a, Show a) => String -> [a] -> (a -> Exp ()) -> PlayerNumber -> Exp ()Source
the same, disregard the event number
onInputChoiceEnum :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (EventNumber -> a -> Exp ()) -> PlayerNumber -> Exp EventNumberSource
triggers a choice input to the user, using an enumerate as input
onInputChoiceEnum_ :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Exp ()) -> PlayerNumber -> Exp ()Source
the same, disregard the event number
onInputChoiceEnumOnce_ :: forall a. (Enum a, Bounded a, Typeable a, Eq a, Show a) => String -> a -> (a -> Exp ()) -> PlayerNumber -> Exp ()Source
the same, suppress the event after first trigger
onInputString :: String -> (EventNumber -> String -> Exp ()) -> PlayerNumber -> Exp EventNumberSource
triggers a string input to the user. The result will be sent to the callback
onInputString_ :: String -> (String -> Exp ()) -> PlayerNumber -> Exp ()Source
asks the player pn to answer a question, and feed the callback with this data.
onInputStringOnce_ :: String -> (String -> Exp ()) -> PlayerNumber -> Exp ()Source
asks the player pn to answer a question, and feed the callback with this data.
Victory, players, output, time and self-number
setVictory :: [PlayerNumber] -> Exp ()Source
set victory to a list of players
giveVictory :: PlayerNumber -> Exp ()Source
give victory to one player
getPlayersNumber :: Exp IntSource
Get the total number of players
output :: String -> PlayerNumber -> Exp ()Source
outputs a message to one player
getSelfRuleNumber :: Exp RuleNumberSource
allows a rule to retrieve its self number (for auto-deleting for example)
Rule samples
autoActivate :: RuleFuncSource
This rule will activate automatically any new rule.
simpleApplicationRule :: RuleFuncSource
This rule establishes a list of criteria rules that will be used to test any incoming rule the rules applyed shall give the answer immediatly
autoMetarules :: Rule -> Exp RuleResponseSource
active metarules are automatically used to evaluate a given rule
applicationMetaRule :: RuleFuncSource
any new rule will be activate if all active meta rules returns True
data ForAgainst Source
vote :: ([(PlayerNumber, ForAgainst)] -> Bool) -> RuleFuncSource
rule that performs a vote for a rule on all players. The provided function is used to count the votes.
unanimity :: [(PlayerNumber, ForAgainst)] -> BoolSource
assess the vote results according to a unanimity
majority :: [(PlayerNumber, ForAgainst)] -> BoolSource
assess the vote results according to an absolute majority (half participants plus one)
activateOrReject :: Rule -> Bool -> Exp ()Source
voteWithTimeLimit :: ([(PlayerNumber, ForAgainst)] -> Bool) -> UTCTime -> RuleFuncSource
rule that performs a vote for a rule on all players. The provided function is used to count the votes, it will be called when every players has voted or when the time limit is reached
createValueForEachPlayer :: Int -> String -> Exp ()Source
create a value initialized for each players manages players joining and leaving
createValueForEachPlayer_ :: String -> Exp ()Source
create and modify values for players
modifyValueOfPlayer :: PlayerNumber -> String -> (Int -> Int) -> Exp ()Source
noPlayPlayer :: PlayerNumber -> RuleFuncSource
Player p cannot propose anymore rules
autoDelete :: Exp ()Source
a rule can autodelete itself (generaly after having performed some actions)
eraseAllRules :: PlayerNumber -> Exp BoolSource
All rules from player p are erased:
Miscellaneous
parse822Time :: String -> UTCTimeSource
andrr :: RuleResponse -> RuleResponse -> Exp RuleResponseSource
andrrs :: [RuleResponse] -> Exp RuleResponseSource
a default rule