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.98 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.97 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.96 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.95 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.94 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.93 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.92 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.91 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.90 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.89 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.88 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.87 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.86 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.85 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.84 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.83 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.82 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.81 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.80 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs
trackler-2.2.1.79 tracks/haskell/exercises/robot-name/examples/success-standard/src/Robot.hs