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 に答える