2013-04-16 14 views
0

嘿所以我嘗試從列表中該字符串列表選擇一個隨機元素然而,當我嘗試選擇添加到列表中理解...器Rvar到字符串列表隨機理解當

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

回答

2

看看choice :: [a] -> RVar a的類型。你的功能應該有String -> String -> RVar String的類型。 RVarT Data.Functor.Identity.Identity [Char]只是RVar String的長同義詞。