Nomyx-Language 0.3.1 → 0.3.2
raw patch · 5 files changed
+14/−9 lines, 5 files
Files
- Nomyx-Language.cabal +1/−1
- src/Language/Nomyx/Definition.hs +3/−2
- src/Language/Nomyx/Examples.hs +2/−2
- src/Language/Nomyx/Rule.hs +1/−1
- src/Language/Nomyx/Vote.hs +7/−3
Nomyx-Language.cabal view
@@ -1,5 +1,5 @@ name: Nomyx-Language-version: 0.3.1+version: 0.3.2 cabal-version: >=1.6 ---Warning: For using "cabal sdist", this patch is needed in cabal: https://github.com/haskell/cabal/pull/1110 ---To allow sdist to work with exported generated modules (Paths_Nomyx_Language)
src/Language/Nomyx/Definition.hs view
@@ -52,7 +52,8 @@ delVar_ :: (V a) -> Nomex () delVar_ v = void $ delVar v -+-- * Message Variable+-- | a MsgVar is a variable with a message attached, allowing to trigger registered functions anytime the var if modified data VEvent a = VUpdated a | VDeleted deriving (Typeable, Show, Eq) data MsgVar a = MsgVar (Msg (VEvent a)) (V a) @@ -119,7 +120,6 @@ f c' (VUpdated v) = update v c' f c' VDeleted = delete c' - -- | get the messsage triggered when the array is filled getMsgVarMessage :: (Typeable a, Show a, Eq a) => (MsgVar a) -> Nomex (Msg (VEvent a)) getMsgVarMessage (MsgVar m _) = return m @@ -133,6 +133,7 @@ getMsgVarName :: (Typeable a, Show a, Eq a) => (MsgVar a) -> String getMsgVarName (MsgVar _ (V varName)) = varName+ -- * Variable arrays -- | ArrayVar is an indexed array with a signal attached triggered at every change.
src/Language/Nomyx/Examples.hs view
@@ -64,8 +64,8 @@ transfer src dst amount = do modifyValueOfPlayer dst accounts (\a -> a + (readDef 0 amount)) modifyValueOfPlayer src accounts (\a -> a - (readDef 0 amount))- newOutput_ ("You gave " ++ amount ++ " to " ++ show dst) src- newOutput_ (show src ++ " gaved you " ++ amount ++ " Ecus") dst+ newOutput_ ("You gave " ++ amount ++ " ecus to player " ++ show dst) src+ newOutput_ ("Player " ++ show src ++ " gaved you " ++ amount ++ "ecus") dst -- | delete a rule
src/Language/Nomyx/Rule.hs view
@@ -79,7 +79,7 @@ createValueForEachPlayer initialValue mv = do pns <- getAllPlayerNumbers v <- newMsgVar_ (getMsgVarName mv) $ map (,initialValue::Int) pns - forEachPlayer (\_-> return ()) + forEachPlayer (const $ return ()) (\p -> modifyMsgVar v ((p, initialValue) : )) (\p -> modifyMsgVar v $ filter $ (/= p) . fst)
src/Language/Nomyx/Vote.hs view
@@ -62,16 +62,20 @@ pns <- getAllPlayerNumbers let toVoteName = name toVote let msgEnd = Message ("Result of votes for " ++ toVoteName) :: Msg [Alts a] - --create an array variable to store the votes. + --create an array variable to store the votes (voteVar :: ArrayVar PlayerNumber (Alts a)) <- newArrayVar_ ("Votes for " ++ toVoteName) pns + --create the voting buttons let askPlayer pn = onInputRadioOnce ("Vote for " ++ toVoteName ++ ":") als (putArrayVar_ voteVar pn) pn inputs <- mapM askPlayer pns let voteData = VoteData msgEnd voteVar inputs countVotes + --set the assessors evalStateT assessors voteData+ --display the vote mapM (\n -> displayVoteVar n ("Votes for " ++ toVoteName ++ ":") voteVar) pns displayVoteResult toVoteName voteData+ --clean the vote at the end cleanVote voteData- return $ msgEnd+ return msgEnd -- | Performs a vote, all the possible alternatives are selected. voteWith_ :: (Votable a) => VoteResult a -> Assessor a -> a -> Nomex (Msg [Alts a]) @@ -192,7 +196,7 @@ showChoice :: (Votable a) => Maybe (Alts a) -> String showChoice (Just a) = show a-showChoice Nothing = "Not Voted "+showChoice Nothing = "Not Voted" showChoices :: (Votable a) => [(Alts a)] -> String showChoices cs = concat $ intersperse ", " $ map show cs