0

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

{-# 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]
4

1 回答 1

2

看看类型choice :: [a] -> RVar a。你的函数应该有 type String -> String -> RVar String。theRVarT Data.Functor.Identity.Identity [Char]只是 的一个很长的同义词RVar String

于 2013-04-16T03:50:22.557 回答