本文介绍了将Data.RVar.RVar [Char]转换为[Char]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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]?

How can I convert Data.RVar.RVar [Char] to [Char] ?

已更新:

我无法导入Data.Random.Source.DevRandom:

I can not import 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

How about something like this: EDIT: Using 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

这篇关于将Data.RVar.RVar [Char]转换为[Char]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:44