【问题标题】:Rvar to String when randomizing list comprehension随机化列表理解时将 Rvar 转换为字符串
【发布时间】:2013-04-16 02:35:19
【问题描述】:

嘿,所以我试图从这个列表字符串列表中选择一个随机元素但是当我尝试将选择添加到列表理解时......

{-# LANGUAGE UnicodeSyntax #-}
import System.Random(randomRIO)
import Data.Random.Extras(choice)
import Data.Char (digitToInt)
...

getConclusion :: String -> String -> [String]
getConclusion operators atoms =
   choice [[atom1] ++ " " ++ [operator] ++ " " ++ [atom2] | atom1 <- atoms, atom2 <-                     atoms, operator <- operators]

...我收到此错误:

/home/joe/Documents/haskell/LAG/main/main.hs: line 56, column 4:
Couldn't match type `Data.RVar.RVarT
                         Data.Functor.Identity.Identity [Char]'
                with `[String]'
  Expected type: [String]
    Actual type: Data.RVar.RVar [Char]
  In the return type of a call of `choice'
  In the expression:
    choice
      [[atom1] ++ " " ++ [operator] ++ " " ++ [atom2] |
         atom1 <- atoms, atom2 <- atoms, operator <- operators]
  In an equation for `getConclusion':
      getConclusion operators atoms
        = choice
            [[atom1] ++ " " ++ [operator] ++ " " ++ [atom2] |
               atom1 <- atoms, atom2 <- atoms, operator <- operators]

【问题讨论】:

    标签: string list haskell random


    【解决方案1】:

    看看choice :: [a] -&gt; RVar a的类型。您的函数应该具有String -&gt; String -&gt; RVar String 类型。 RVarT Data.Functor.Identity.Identity [Char] 只是 RVar String 的同义词。

    【讨论】:

      猜你喜欢
      • 2018-05-22
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 2012-03-10
      • 2019-01-15
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      相关资源
      最近更新 更多