2

cabal 安装随机附加组件

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
4

1 回答 1

3

像这样的东西怎么样:编辑:使用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
于 2012-10-29T12:19:08.990 回答