嘿所以我试图从这个列表字符串中选择一个随机元素然而当我尝试添加选项到列表理解...

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

===============>>#1 票数:2

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

  ask by user2150839 translate from so

未解决问题?本站智能推荐: