2013-04-17 81 views
2
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 

有沒有一種很好的方法來解決這個問題?我收到此錯誤:+運算符與字符串和IO字符串

/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 
+0

如果回答您的問題,請不要忘記標記答案爲已接受。如果還不清楚,請隨時在評論中澄清問題,或者通過更多信息更新您的問題,而不是如此。 – Davorak

回答

5

因爲getConclusion返回的值是IO String你不能簡單地與功能上展開值操作使用它。要麼首先使用x <- getConclusion operators atom打開數值,要麼使用函數組合使用fmap