Created
May 13, 2018 07:17
-
-
Save n4to4/be0792103ad7eafbf7f5bec8062cca52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
module Main where | |
import Control.Monad.State | |
import System.Random | |
type GenAction m = forall a. (Random a) => m a | |
type GenActionR m = forall a. (Random a) => (a, a) -> m a | |
data Player = Player | |
{ playerName :: String | |
, playerPos :: (Double, Double) | |
} deriving (Eq, Ord, Show) | |
genRandom :: (RandomGen g) => GenAction (State g) | |
genRandom = state random | |
genRandomR :: (RandomGen g) => GenActionR (State g) | |
genRandomR range = state (randomR range) | |
randomPlayer :: (MonadIO m) => GenActionR m -> m Player | |
randomPlayer genR = do | |
liftIO $ putStrLn "Generating random player..." | |
len <- genR (8, 12) | |
name <- replicateM len $ genR ('a', 'z') | |
x <- genR (-100, 100) | |
y <- genR (-100, 100) | |
liftIO $ putStrLn "Done." | |
return $ Player name (x, y) | |
main :: IO () | |
main = randomPlayer randomRIO >>= print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment