【发布时间】:2010-09-22 13:01:07
【问题描述】:
我正在使用行功能来获取输入并在将其发送到函数之前拆分许多变量。请查看运行函数并告诉我为什么会出现以下错误。似乎它应该只将 ln 中的第一个字符串分配给 seq,但我得到一个错误。
错误:不诚实.hs:33:11: 无法将预期类型“[t]”与推断类型“Char”匹配 在“do”表达式中: seq import Char maximumInd :: (Double, Double) -> Int maximumInd (d1,d2) | maximum [d1,d2] == d1 = 1 | maximum [d1,d2] == d2 = 2 scoreFunction :: String -> Int -> [Double] -> [Double] -> Double -> Double -> (Double,Double) scoreFunction string (-1) l1 l2 t1 t2 = (0.5, 0.5) scoreFunction string index l1 l2 t1 t2 = ((fst (scoreFunction string (index-1) l1 l2 t1 t2)) * (l1!!num) * (tr (maximumInd (scoreFunction string (index-1) l1 l2 t1 t2))!!1), (snd (scoreFunction string (index-1) l1 l2 t1 t2)) * (l2!!num) * (tr (maximumInd (scoreFunction string (index-1) l1 l2 t1 t2))!!2)) where num = digitToInt (string!!index) tr n | n == 1 = l1 | n == 2 = l2 --split is stolen from teh webs http://julipedia.blogspot.com/2006/08/split-function-in-haskell.html split :: String -> Char -> [String] split [] delim = [""] split (c:cs) delim | c == delim = "" : rest | otherwise = (c : head rest) : tail rest where rest = split cs delim readDouble :: String -> Double readDouble s = read s :: Double listDouble :: String -> [Double] listDouble s = map readDouble $ split s ' ' run :: String -> String run s = do ln <- lines s seq <- ln!!0 states <- ln!!1 l1 <- listDouble (ln!!2) l2 <- listDouble (ln!!3) tr1 <- readDouble (ln!!4) tr2 <- readDouble (ln!!5) show maximumInd (scoreFunction seq (length seq) l1 l2 tr1 tr2) main = do putStrLn "Please compose a test job for Viterbi." putStrLn "First line: A sequence with language [1,9]." putStrLn "Second line: The number of states." putStrLn "For the next 2 lines: space delimited emission probabilities." putStrLn "For the 2 lines after that, transmission probabilities." putStrLn "Then do ./casino < filename " interact run【问题讨论】:
标签: string haskell functional-programming