Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell string list through lines
    text
    copied!<p>I'm using the lines functionality to take an input and split up many variables before sending it off to a function. Please look at the run function and tell me why I get the following error. It seems like it should just assign the first string in ln to seq, but I get an error.</p> <pre> ERROR:dishonest.hs:33:11: Couldn't match expected type `[t]' against inferred type `Char' In a 'do' expression: seq &lt;- ln !! 0 In the expression: do ln &lt;- lines s seq &lt;- ln !! 0 states &lt;- ln !! 1 l1 &lt;- listDouble (ln !! 2) .... In the definition of `run': run s = do ln &lt;- lines s seq &lt;- ln !! 0 states &lt;- ln !! 1 .... code follows... <code> 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 &lt;- lines s seq &lt;- ln!!0 states &lt;- ln!!1 l1 &lt;- listDouble (ln!!2) l2 &lt;- listDouble (ln!!3) tr1 &lt;- readDouble (ln!!4) tr2 &lt;- 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 &lt; filename " interact run </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload