我想實現Haskell的標準字功能。我正在使用State Monad來解決問題。異常:模式匹配失敗Haskell
我的代碼是:
type WorS = ([String],String,String)
words' :: State WorS [String]
words' = do
(lwords, words, x:xs) <- get
case x:xs of
(' ':xs) -> (put (words:lwords, [], xs) >> words')
([]) -> return lwords
(_:xs)-> (put (lwords, words ++ [x], xs) >> words')
run_word' :: String ->[String]
run_word' x = reverse $ fst (runState words' ([], [], x))
當我這樣做:
run_word' "guns and roses"
我得到這個錯誤:
Exception: Pattern match failure in do expression
的代碼加載在ghci中沒有任何錯誤。我究竟做錯了什麼?
的[在功能上非詳盡模式(可能重複http://stackoverflow.com/questions/8435575/non -exhaustive-patterns-in-function) – 2013-02-15 20:54:39