嘿所以我试图从这个列表字符串中选择一个随机元素然而当我尝试将选项添加到列表理解中时...
{-# 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]
答案 0 :(得分:2)
看一下choice :: [a] -> RVar a
的类型。您的函数应该具有String -> String -> RVar String
类型。 RVarT Data.Functor.Identity.Identity [Char]
只是RVar String
的长同义词。