我想实现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