{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Effectful.Crypto.RNG.Effect where

import Data.ByteString (ByteString)
import Effectful
import Effectful.Dispatch.Dynamic
import System.Random
import Crypto.RNG.Class

-- | Provide the ability to generate random numbers.
data RNG :: Effect where
  RandomBytes :: Int -> RNG m ByteString
  Random      :: Uniform a => RNG m a
  RandomR     :: UniformRange a => (a, a) -> RNG m a

type instance DispatchOf RNG = 'Dynamic

instance RNG :> es => CryptoRNG (Eff es) where
  randomBytes :: Int -> Eff es ByteString
randomBytes = RNG (Eff es) ByteString -> Eff es ByteString
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (RNG (Eff es) ByteString -> Eff es ByteString)
-> (Int -> RNG (Eff es) ByteString) -> Int -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RNG (Eff es) ByteString
forall (m :: Type -> Type). Int -> RNG m ByteString
RandomBytes
  random :: Eff es a
random      = RNG (Eff es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send RNG (Eff es) a
forall a (m :: Type -> Type). Uniform a => RNG m a
Random
  randomR :: (a, a) -> Eff es a
randomR     = RNG (Eff es) a -> Eff es a
forall (e :: Effect) (es :: [Effect]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (RNG (Eff es) a -> Eff es a)
-> ((a, a) -> RNG (Eff es) a) -> (a, a) -> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, a) -> RNG (Eff es) a
forall a (m :: Type -> Type). UniformRange a => (a, a) -> RNG m a
RandomR