diff options
| -rw-r--r-- | HsBot.hs | 49 | ||||
| -rw-r--r-- | Main.hs | 7 |
2 files changed, 22 insertions, 34 deletions
@@ -3,7 +3,7 @@ module Main (main) where import Control.Monad (forM) -import Control.Monad.State +--import Control.Monad.State import IO import Monad import Random @@ -27,10 +27,6 @@ instance Ord Karma where data Conf = Conf { users :: [User], karmas :: [Karma] } deriving (Show, Read) -type StateTrans st = s -> (t, s) - - - data User = User { userName :: String, userPts :: Int } deriving (Show, Read) instance Eq User where x == y = (userPts x) == (userPts y) @@ -125,33 +121,18 @@ readline = do _ -> putStrLn "" -data MyType = MT Int Bool Char Int deriving Show - -{- Using the State monad, we can define a function that returns - a random value and updates the random generator state at - the same time. --} -getAny :: (Random a) => State StdGen a -getAny = do g <- get - (x,g') <- return $ random g - put g' - return x - --- similar to getAny, but it bounds the random value returned -getOne :: (Random a) => (a,a) -> State StdGen a -getOne bounds = do g <- get - (x,g') <- return $ randomR bounds g - put g' - return x - -{- Using the State monad with StdGen as the state, we can build - random complex types without manually threading the - random generator states through the code. --} -makeRandomValueST :: StdGen -> (MyType, StdGen) -makeRandomValueST = runState (do n <- getOne (1,100) - b <- getAny - c <- getOne ('a','z') - m <- getOne (-n,n) - return (MT n b c m)) +newtype Transformator a = Transformator { execTransformator :: (a, Conf) } + +runTransformator = execTransformator +record s = Transformator ([s], ()) + +instance Monad Transformator where + return c = Transformator ([], c) + c >>= f = let (s, c') = execTransformator c + s' = f s + in Transformator (s', c') + + +main :: IO () +main = putStrLn "Good bye" @@ -0,0 +1,7 @@ +-- Karmabot By Paul C. Buetow + +module Main (main) where + +import HsBot + +main = start |
