, , . - , , a length :: [a] -> Int. ( ), , , , , . , firstCoin secondCoin thirdCoin , (Bool, Bool, Bool), , Bool.
, Haskell , , Rank-2. , , GHCi, ( " " ), , GHCi.
firstCoin secondCoin thirdCoin .. , Bool: random (.. , random ). , :
threeCoins :: StdGen -> (Bool, Bool, Bool)
threeCoins gen =
let firstCoin, secondCoin, thirdCoin :: Random r => r
(firstCoin, newGen) = random gen
(secondCoin, newGen') = random newGen
(thirdCoin, newGen'') = random newGen'
in (firstCoin, secondCoin, thirdCoin)
, , ,
{-
.
, . , r , random, , , - .
, , , :
import System.Random
import Data.Random
threeCoins :: RVar (Bool, Bool, Bool)
threeCoins = do
firstCoin <- uniform False True
secondCoin <- uniform False True
thirdCoin <- uniform False True
return (firstCoin, secondCoin, thirdCoin)
main = print . sampleState threeCoins $ mkStdGen 21
, firstCoin secondCoin thirdCoin , .
, , , ,
import Control.Monad (replicateM)
threeCoins :: RVar (Bool, Bool, Bool)
threeCoins = do
[firstCoin,secondCoin,thirdCoin] <- replicateM 3 $ uniform False True
return (firstCoin, secondCoin, thirdCoin)