module CoinFlip where


import FunQ

-- | Given two values, will return either of them with a 50% probability.

-- Example usage:
--   :l examples/CoinFlip.hs -- Load the haskell file
--   run $ coinFlip "hard brackets" "parenthesis"

coinFlip :: a -> b -> QM (Either a b)
coinFlip :: a -> b -> QM (Either a b)
coinFlip left :: a
left right :: b
right = do
    QBit
q <- Bit -> QM QBit
new 0
    QBit
q <- QBit -> QM QBit
hadamard QBit
q
    Bit
b <- QBit -> QM Bit
measure QBit
q
    Either a b -> QM (Either a b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either a b -> QM (Either a b)) -> Either a b -> QM (Either a b)
forall a b. (a -> b) -> a -> b
$ if Bit
b Bit -> Bit -> Bool
forall a. Eq a => a -> a -> Bool
== 0 then a -> Either a b
forall a b. a -> Either a b
Left a
left else b -> Either a b
forall a b. b -> Either a b
Right b
right