I'm trying to hash text using Crypto.Hash modules on replit.com, I don't know how to resolve this failure: Could not find module ‘Crypto.Hash’
Code:
import Crypto.Hash (hashWith, SHA256(..))
import Data.ByteString (ByteString)
main = do
putStrLn "Hello"
putStrLn "World"
hashWith SHA256 ("hello" :: ByteString)
I will be very grateful for your help!!!
CodePudding user response:
It looks like replit.com
is Nix based, and it uses a replit.nix
configuration file to configure the Nix environment, including loaded GHC packages.
So, one way to get this working is to edit the replit.nix
file. (By default, it won't be shown in the "Files" tab, but you can click the vertical "..." in the top-right corner and select "Show hidden files" to view it.) Modify it to look something like:
{ pkgs }: {
deps = [
(pkgs.haskellPackages.ghcWithPackages (pkgs: [
pkgs.cryptonite
]))
pkgs.haskell-language-server
];
}
Now, when you run the source, it should reconfigure the Nix environment and load the required cryptonite
package. You may need to modify your code slightly, too, as it uses an OverloadedStrings
extension, and hashWith
isn't an IO action. I got the following Main.hs
to work:
{-# LANGUAGE OverloadedStrings #-}
import Crypto.Hash (hashWith, SHA256(..))
import Data.ByteString (ByteString)
main = do
print $ hashWith SHA256 ("hello" :: ByteString)