Skip to content

Instantly share code, notes, and snippets.

@geekingfrog
Last active July 13, 2019 08:02
Show Gist options
  • Save geekingfrog/8c2420bee858e2ed57b5d026bd44fd53 to your computer and use it in GitHub Desktop.
Save geekingfrog/8c2420bee858e2ed57b5d026bd44fd53 to your computer and use it in GitHub Desktop.
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Orphan where
import qualified Hedgehog as H
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import qualified Crypto.PubKey.Curve25519 as Curve25519
import Crypto.Random.Types (MonadRandom (..))
import qualified Data.ByteArray as BA
-- the orphan instance I'd like to get rid of
instance Monad m => MonadRandom (H.GenT m) where
getRandomBytes size = do
bytes <- Gen.bytes (Range.singleton size)
pure $ BA.convert bytes
genSecretKeyOrphan :: (H.MonadGen m, MonadRandom m) => m Curve25519.SecretKey
genSecretKeyOrphan = Curve25519.generateSecretKey
newtype Foo a = Foo { runFoo :: H.Gen a }
deriving (Functor, Applicative, Monad, H.MonadGen)
instance MonadRandom Foo where
getRandomBytes size = do
bytes <- Gen.bytes (Range.singleton size)
pure $ BA.convert bytes
-- -- question is, how do I use that?
-- genSecretKey :: (H.MonadGen m) => m Curve25519.SecretKey
-- -- genSecretKey = runFoo $ Foo $ do ????
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment