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.180 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.179 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.178 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.177 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.176 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.175 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.174 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.173 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.172 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.171 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.170 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.169 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.167 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.166 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.165 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.164 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.163 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.162 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.161 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.160 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs