Sha256: 83921bf773bb17d7ab1b64ae311f4b9afd295cf28f2788834c9e7f95f7acb3fa

Contents?: true

Size: 621 Bytes

Versions: 374

Compression:

Stored size: 621 Bytes

Contents

module Robot (Robot, mkRobot, robotName, resetName) where

import Control.Concurrent (MVar, readMVar, swapMVar, newMVar)
import Control.Monad (void)
import System.Random (randomRIO)

newtype Robot = Robot { robotNameVar :: MVar String }

mkRobot :: IO Robot
mkRobot = fmap Robot $ generateName >>= newMVar

resetName :: Robot -> IO ()
resetName r = void (generateName >>= swapMVar (robotNameVar r))

robotName :: Robot -> IO String
robotName = readMVar . robotNameVar

generateName :: IO String
generateName = mapM randomRIO [ letter, letter, digit, digit, digit ]
  where
    letter = ('A', 'Z')
    digit  = ('0', '9')

Version data entries

374 entries across 374 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.138 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.137 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.136 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.135 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.134 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.133 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.132 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.131 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.130 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.129 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.128 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.127 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.126 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.125 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.124 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.123 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.122 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.121 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.120 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs