Ad
Haskell RSA Crypto Random Generator Type
My goal is to generate a keypair using generateKeyPair
from Codec.Crypto.RSA
.
This function requires a generator of type RandomGen
. I have tried to make this generator with newGenIO
, but I'm having a hard time specifying its type.
import qualified Codec.Crypto.RSA as Crypto
import Crypto.Random
someFunc = do
let g = newGenIO :: CryptoRandomGen (IO SystemRandom)
let keyPair = Crypto.generateKeyPair g 10
Haskell suggested CryptoRandomGen SystemRandom
when I didn't specify a type after newGenIO
.
This is the error message that comes when trying to run the code.
• Expected a type, but
‘CryptoRandomGen (IO SystemRandom)’ has kind
‘Constraint’
Does anyone know what type I have use to get it to work?
Ad
Answer
Try replacing that line with this one:
g <- newGenIO :: IO SystemRandom
When you want a specific instance of a class, you just use the type, rather than specifying the class again. And to get something out of IO, you need to bind into it rather than just using =
.
Ad
source: stackoverflow.com
Related Questions
- → How do you convert from an Unboxed Vector to a JS TypedArray on GHCJS?
- → Why do we need `startWatching` function from WalletApi?
- → Plutus Interpreter Error in Plutus Playground
- → CRUD pattern on Haskell Persistent
- → Yesod and MySQL connection issue
- → How to use the State Monad
- → Why this Either-monad code does not type check?
- → How to define (+) function for custom data type?
- → Can this prime sieve code be further simplified in Haskell?
- → Haskell usnig termination in a function
- → Sets in Haskell
- → Which Haskell package contains given module
- → How to tell HSpec where to look for the source files to be tested
Ad