module Control.Wire.Prefab.Random
(
noise,
noiseR,
noiseF,
noiseF1,
wackelkontakt
)
where
import Control.Arrow
import Control.Monad
import Control.Wire.Classes
import Control.Wire.Types
import System.Random
class Arrow (>~) => WRandom (>~) where
noise :: Random b => Wire e (>~) a b
noiseR :: Random b => Wire e (>~) (b, b) b
wackelkontakt :: Wire e (>~) Double Bool
instance MonadRandom m => WRandom (Kleisli m) where
noise = mkFixM (liftM Right . const getRandom)
noiseR = mkFixM (liftM Right . getRandomR)
wackelkontakt =
mkFixM $ \p -> do
s <- getRandom
return (Right (not (s >= p)))
noiseF :: WRandom (>~) => Wire e (>~) a Double
noiseF = noise
noiseF1 :: (Arrow (Wire e (>~)), WRandom (>~)) => Wire e (>~) a Double
noiseF1 = ((*2) . pred) ^<< noise