嘿,所以我试图从这个列表字符串列表中选择一个随机元素但是当我尝试向列表理解添加选择时......
{-# 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]