gpt4 book ai didi

haskell - 将 GHC.Int.Int64 转换为 Int

转载 作者:行者123 更新时间:2023-12-04 13:26:58 24 4
gpt4 key购买 nike

我正在尝试生成一个随机的懒惰 ByteString与懒惰的 ByteString 长度相同我已经有了。

所以我取ByteString的长度并将其输入 getEntropy像这样:

import qualified Data.ByteString.Lazy.Char8 as L
import qualified System.Entropy as SE

string :: L.ByteString
string = L.pack "Hello world!"

randomString :: IO L.ByteString
randomString = L.fromChunks . (:[]) <$> SE.getEntropy (L.length string)

(使用 L.fromChunks . (:[]) 从严格的 ByteString 转换为懒惰的。)

问题是 SE.getEntropyInt -> IO ByteString 类型而 L.lengthL.ByteString -> GHC.Int.Int64 类型.

如何转换 Int64Int ?

最佳答案

你可以转任何Integral输入另一个 Num使用 fromIntegral 输入:

fromInt64ToInt :: Int64 -> Int
fromInt64ToInt = fromIntegral

关于haskell - 将 GHC.Int.Int64 转换为 Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26967241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com