gpt4 book ai didi

haskell - 将 Data.RVar.RVar [Char] 转换为 [Char]

转载 作者:行者123 更新时间:2023-12-04 05:26:47 25 4
gpt4 key购买 nike

cabal install random-extras


Prelude Data.Random.Extras> import Data.Random.Extras
Prelude Data.Random.Extras> let s = shuffle "somestring"
Prelude Data.Random.Extras> s

<interactive>:1:1:
No instance for (Show (Data.RVar.RVar [Char]))
arising from a use of `print'
Possible fix:
add an instance declaration for (Show (Data.RVar.RVar [Char]))
In a stmt of an interactive GHCi command: print it

如何将 Data.RVar.RVar [Char] 转换为 [Char] ?

更新:

我无法导入 Data.Random.Source.DevRandom:
Prelude> import Data.Random hiding (shuffle)
Prelude Data.Random> import Data.Random.Source.DevRandom

<no location info>:
Could not find module `Data.Random.Source.DevRandom':
Use -v to see a list of the files searched for.

但是:
[59]: cabal install random-fu
Resolving dependencies...
No packages to be installed. All the requested packages are already installed.
If you want to reinstall anyway then use the --reinstall flag.
[60]: cabal install random-source
Resolving dependencies...
No packages to be installed. All the requested packages are already installed.
If you want to reinstall anyway then use the --reinstall flag.

更新 2:
*Main System.Random> import Data.Random hiding (shuffle)
*Main System.Random Data.Random> import Data.Random.Source.Std
*Main System.Random Data.Random Data.Random.Source.Std> import Data.Random.Extras
*Main System.Random Data.Random Data.Random.Source.Std Data.Random.Extras> let reversed = runRVar (shuffle "somestring") StdRandom

<interactive>:1:16:
Ambiguous type variable `m0' in the constraints:
(MonadRandom m0) arising from a use of `runRVar'
at <interactive>:1:16-22
(Monad m0) arising from a use of `runRVar' at <interactive>:1:16-22
Probable fix: add a type signature that fixes these type variable(s)
In the expression: runRVar (shuffle "somestring") StdRandom
In an equation for `reversed':
reversed = runRVar (shuffle "somestring") StdRandom

最佳答案

这样的事情怎么样:编辑 : 使用 StdRandom

import Data.Random hiding (shuffle)
import Data.Random.Source.Std
import Data.Random.Extras

reversed = runRVar (shuffle "somestring") StdRandom

test = do
x <- reversed
putStrLn x

关于haskell - 将 Data.RVar.RVar [Char] 转换为 [Char],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13120612/

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