Sha256: b057bf24efb024728e795c19355efe55f020e30aa7732daa5530695555012a38

Contents?: true

Size: 618 Bytes

Versions: 22

Compression:

Stored size: 618 Bytes

Contents

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

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

data 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

22 entries across 22 versions & 1 rubygems

Version Path
trackler-2.0.1.0 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.10 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.9 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.8 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.7 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.6 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.5 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.4 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.3 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.0.0.2 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-2.0.0.1 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-2.0.0.0 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.4.1 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.4.0 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.3.0 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.2.1 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.2.0 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.1.2 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.1.1 tracks/haskell/exercises/robot-name/src/Example.hs
trackler-1.0.1.0 tracks/haskell/exercises/robot-name/src/Example.hs