带有String和IO String的++运算符

use*_*839 2 string io haskell

explandDol :: String -> String -> [String] -> IO String
explandDol conclusion operators atoms =
    let (ys,zs) = splitAt (head (take 1 replacement)) conclusion in ys ++ getConclusion     operators atoms ++ (tail zs)
    where replacement = elemIndices '$' conclusion



getConclusion :: String -> [String] -> IO String
getConclusion operators atoms =
   runRVar (choice [atom1 ++ " " ++ [operator] ++ " " ++ atom2 | atom1 <- atoms, atom2 <-    atoms, operator <- operators,checkAtoms atom1 atom2]) StdRandom
Run Code Online (Sandbox Code Playgroud)

有没有好办法解决这个问题?我收到此错误:

/home/joe/Documents/haskell/LAG/main/main.hs: line 73, column 69:
  Couldn't match expected type `IO String' with actual type `[Char]'
  In the expression: ys ++ getConclusion operators atoms ++ (tail zs)
  In the expression:
    let (ys, zs) = splitAt (head (take 1 replacement)) conclusion
    in ys ++ getConclusion operators atoms ++ (tail zs)
  In an equation for `explandDol':
      explandDol conclusion operators atoms
        = let (ys, zs) = splitAt (head (take 1 replacement)) conclusion
          in ys ++ getConclusion operators atoms ++ (tail zs)
        where
            replacement = elemIndices '$' conclusion
/home/joe/Documents/haskell/LAG/main/main.hs: line 73, column 75:
  Couldn't match expected type `[Char]' with actual type `IO String'
  In the return type of a call of `getConclusion'
  In the first argument of `(++)', namely
    `getConclusion operators atoms'
  In the second argument of `(++)', namely
    `getConclusion operators atoms ++ (tail zs)'
/home/joe/Documents/haskell/LAG/main/main.hs: line 73, column 75:
  Warning: Redundant bracket
  Found:
    getConclusion operators atoms ++ (tail zs)
  Why not:
    getConclusion operators atoms ++ tail zs
Run Code Online (Sandbox Code Playgroud)

Adr*_*ian 5

因为返回的值getConclusionIO String您不能简单地将它与在未包装的值上运行的函数一起使用.首先使用x <- getConclusion operators atom或者如果您想要使用函数组合来展开值fmap.